Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Textbox inside datagrid - Value doesn't change for the textbox
4 replies. Latest Post by mehtapratik on July 6, 2009.
(0)
mehtapratik
Member
269 points
302 Posts
07-03-2009 3:01 AM |
Hi All,
My problem is when the textbox has value(e.g 2) and if I edit to a new value with appending 1 to existing value(e.g 21) than it won't work and if I remove the old value and type a new value(e.g 3) than it works.. any idea??
<data:DataGrid MinHeight="100" ItemsSource="{Binding POSProductsList,Source={StaticResource POSViewModel},Mode=TwoWay}" RowHeight="30" HorizontalAlignment="Stretch" Height="Auto" Width="Auto" Margin="10" HorizontalContentAlignment="Left" AutoGenerateColumns="false"> <data:DataGrid.Columns> <data:DataGridTemplateColumn Header="Qty" Width="Auto" MinWidth="80" MaxWidth="300" > <data:DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5,0,0,0" Text="{Binding Quantity,Mode=TwoWay}"></TextBlock> </DataTemplate> </data:DataGridTemplateColumn.CellTemplate> <data:DataGridTemplateColumn.CellEditingTemplate> <DataTemplate> <TextBox LostFocus="txtQuantity_LostFocus" Text="{Binding Quantity,Mode=TwoWay}" Width="60" VerticalAlignment="Center" HorizontalAlignment="Center" x:Name="txtQuantity" > </TextBox> </DataTemplate> </data:DataGridTemplateColumn.CellEditingTemplate> </data:DataGridTemplateColumn> </data:DataGrid.Columns> </data:DataGrid>
Here my model class public class POSViewModel : ViewModelBase {
ObservableCollection<Model.POSProducts> _posproductslist; public ObservableCollection<Model.POSProducts> POSProductsList { get { return _posproductslist; } set { _posproductslist = value; this.RaisePropertyChanged("POSProductsList"); } }
Here my POSProducts class
public class POSProducts : ModelBase {
private int? _quantity; public int? Quantity { get { return _quantity; } set { try { if (value < 0) { MessageBox.Show("Invalid Quantity"); return; } _quantity = value; this.RaisePropertyChanged("Quantity"); this.RaisePropertyChanged("TotalCost"); } catch { MessageBox.Show("Invalid Quantity"); } } }
}
ken tucker
All-Star
16288 points
2,485 Posts
07-03-2009 10:10 AM |
The simple answer here is the user entered bad data so your property is never updated.
You can handle the NotifyOnValidationError to catch when the user enters bad data
http://msdn.microsoft.com/en-us/library/system.windows.data.binding.notifyonvalidationerror%28VS.95%29.aspx
07-03-2009 5:01 PM |
Thanks ken for your answer, but I think you misunderstood the question. my problem is user is entering correct data still the value doesn't change if the textbox has already value and if i remove that value and than change than it will work
07-06-2009 1:41 AM |
I am using Silverlight 3
07-06-2009 2:13 AM |
I found that this is the bug of silverlight binding.. here is the details
http://silverlight.net/forums/t/35136.aspx