How to add a blank new row to WPF DataGrid automatically when user start editing current row
I have a DataGrid
bind with ObservableCollection<MydataObject> MyDatalist
With all the default settings, if user change the focus from the DataGrid
(e.g. clicked a button
) while editing a cell, all the data showing in the DataGrid
includes the one the user is editing are stored to MyDatalist
, thi开发者_如何学运维s is great, but the user need to hit "Tab" (while in the last cell) or "Enter" to create a new row.
I want the DataGrid to generate a new row automatically when user start editing any cell of the last row. I have tried the CurrentCellChanged
event and I can have the new row automatically created by doing this:
void dataGrid1_CurrentCellChanged(object sender, EventArgs e)
{
dataGrid1.CommitEdit();
}
However, with this implemented, if user change the focus from the DataGrid
(e.g. clicked a button
) while editing a cell, the one that the user is editing is not stored to MyDatalist
, How can I have this feature back with the new row automatically added?
OK here is a Binding.UpdateSourceTrigger
Property set this solved my problem:
Binding="{Binding Path=field1, UpdateSourceTrigger=PropertyChanged}"
精彩评论