Reputation: 3
I have datagrid in which one of the column is Textbox control, have set the binding as twoway. the grid is binded to a observable collection. Issue : If I enter some value in text box, collection get populated. now if I clears that textbox the same has not been reflected to the collection. my binded property is nullable.
Thanks N Advance
Upvotes: 0
Views: 801
Reputation: 3854
I'm not sure where your problem might be exactly, but I've tried the following and it works as expected:
I have a simple Person class:
public class Person : ObservableObject
{
private string name;
public string Name
{
get { return name; }
set
{
if (name == value)
return;
name = value;
RaisePropertyChanged(() => Name);
}
}
private int? age;
public int? Age
{
get { return age; }
set
{
if (age == value)
return;
age = value;
RaisePropertyChanged(() => Age);
}
}
}
I also have a simple ViewModel with an ObservableCollection<Person>
called Data
. Ans, here's my XAML:
<sdk:DataGrid Name="dataGrid" ItemsSource="{Binding Data}" AutoGenerateColumns="False"
SelectedItem="{Binding SelectedPerson, Mode=TwoWay}" Grid.Row="1">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Binding="{Binding Name, Mode=TwoWay}"/>
<sdk:DataGridTextColumn Binding="{Binding Age, Mode=TwoWay}"/>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
I checked how it's working by setting a breakpoint in the Setter for my Age
property, and it shows the value comming in as null
Hope this helps ;)
Upvotes: 0
Reputation: 1
You may use
<TextBox IsReadOnly="True" Text="{Binding BUApprovalQty, Mode=TwoWay, TargetNullValue=''}"></TextBox>
Upvotes: 0
Reputation: 13606
Check the Output window in Visual Studio for binding errors. You should see a warning that there is no implicit conversion from an empty string to an Integer.
You could use a ValueConverter to perform this task.
See this related question for other approaches. Note that some may not apply as the focus there is WPF.
WPF binding not working properly with properties of int type
Upvotes: 1