I have a xamDataGrid that is bound to a strongly typed dataset and I'm wondering how do i insert a row into the xamDataGrid when the user clicks the 'Add' button. I've tried a few things but no luck.
On the 'Delete' button I have this code which works well, "
xamDataGridWebMaintenance.ExecuteCommand(
DataPresenterCommands.DeleteSelectedDataRecords);", just wondering what best to do when the user clicks the 'Add' button.
I would also like to defualt the value for the PK column which is collapsed to the user.
Troy
Ok. i think i've found another solution to this that works for me. This code also move to cell below if enter is pressed within the grid. Enjoy.
Handle PreviewKeyDown
public static void DataGridPreviewKeyDown(object sender, KeyEventArgs e) { var grid = sender as XamDataGrid; if (grid == null) return; if (e.Key == Key.Enter) { if (grid.RecordManager.CurrentAddRecord == grid.ActiveRecord) { grid.ExecuteCommand(DataPresenterCommands.EndEditModeAndCommitRecord); grid.ActiveRecord = grid.RecordManager.CurrentAddRecord; grid.ExecuteCommand(DataPresenterCommands.CellFirstInRecord); } else { grid.ExecuteCommand(DataPresenterCommands.EndEditModeAndCommitRecord); grid.ExecuteCommand(DataPresenterCommands.CellBelow); } } }
Hi Masum, thanks for the solution. however i'm not convinced this works perfectly. When i'm committing a row in the grid, this logic also kicks in just because my grid allows add new row. (xamDataGrid1.DefaultFieldLayout.AllowAddNewResolved == true)
Is there a way to tell the committed row is a new row? if i can use this as a check in the event handler, i think it will work well.
Thanks
Hello
This question solution is like this.
You can add following code .you can add XamDataGrid ExecutedCommand event.
private void xamDataGrid1_ExecutedCommand(object sender, Infragistics.Windows.Controls.Events.ExecutedCommandEventArgs e) { if (e.Command == DataPresenterCommands.EndEditModeAndCommitRecord) { if (xamDataGrid1.DefaultFieldLayout.AllowAddNewResolved == true) { xamDataGrid1.ExecuteCommand(DataPresenterCommands.CellAbove); xamDataGrid1.ExecuteCommand(DataPresenterCommands.CellFirstInRecord); xamDataGrid1.ExecuteCommand(DataPresenterCommands.StartEditMode);
}
That's it.......
Have a nice Day......
Hello Alex,
it did work with XamDataGrid.
My problem now is that I have fields in every Record in XamDataGrid, and I want to add new "Records" in the fields.
Everytime CommitAddRecord is called, a new Record will be added to XamDataGrid but not in the ActiveRecord.
Thats why I have to use "Press Enter" or "Move the focus of the fields manually by click" to add the Record in the fields.
Is it possible to do this automatically (within code)?
Thanks.
It did work for XamDataGrid. But I also have fields in the XamDataGrid which also has a list of "records".
For these fields I have to click another Records or press enter in order to add new record (inside the fields). Is it possible to make this automatically?
Everytime I call the CommitAddRecord, a new Record will be added for XamDataGrid but not for the fields in the ActiveRecord.