Skip to main content

Microsoft Silverlight

Answered Question Textbox inside datagrid - Value doesn't change for the textbox RSS Feed

(0)

mehtapratik
mehtapratik

Member

Member

269 points

302 Posts

Textbox inside datagrid - Value doesn't change for the textbox

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");
                }
            }
        }

}

 

 

 

Pratik Mehta
Espirit Softwares Pvt. Ltd.
India.

ken tucker
ken tucker

All-Star

All-Star

16198 points

2,470 Posts

Re: Textbox inside datagrid - Value doesn't change for the textbox

 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

mehtapratik
mehtapratik

Member

Member

269 points

302 Posts

Re: Re: Textbox inside datagrid - Value doesn't change for the textbox

 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

Pratik Mehta
Espirit Softwares Pvt. Ltd.
India.

mehtapratik
mehtapratik

Member

Member

269 points

302 Posts

Re: Re: Re: Textbox inside datagrid - Value doesn't change for the textbox

 I am using Silverlight 3

Pratik Mehta
Espirit Softwares Pvt. Ltd.
India.

mehtapratik
mehtapratik

Member

Member

269 points

302 Posts

Answered Question

Re: Re: Re: Re: Textbox inside datagrid - Value doesn't change for the textbox

 I found that this is the bug of silverlight binding.. here is the details

http://silverlight.net/forums/t/35136.aspx

Pratik Mehta
Espirit Softwares Pvt. Ltd.
India.
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities