WPF datagrid edit row not working
I want to set a cell in my WPF DataGrid
on a 开发者_开发技巧button click.
I fill a WPF DataGrid
like this:
myDataGrid.ItemsSource = GetMyList();
The DataGrid
is set to autoGenerateColumns
. I get my list using a mySql select.
The objects in my list implement the INotifyPropertyChanged
interface.
On my button click I do this:
MyObject o = (MyObject)myDataGrid.SelectedItem;
o.Checkin = DateTime.Now; //set date on button click is what i want
The data is set but the DataGrid
doesn't update its view. Why?
Edited:
I implement the INotifyPropertyChanged
interface like this:
private void NotifyPropertyChanged(String info) {
if (PropertyChanged != null) {
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
public DateTime Checkin {
get {return this.checkin;}
set {
this.checkin= value;
NotifyPropertyChanged("Checkin");
}
}
}
this did the trick:
myDataGrid.Items.Refresh();
what happens if you dont use autogeneratecolumns and explicitly set the binding in your columnsdefinition to TwoWay?
<DataGridTextColumn Header="Checkin " >
<DataGridTextColumn.Binding>
<Binding Path="Checkin " Mode="TwoWay">
</Binding>
</DataGridTextColumn.Binding>
</DataGridTextColumn>
精彩评论