I have a grid view sorted by a date column, users can add records to the grid view via the "Click here to add new item" row, a context menu, or ribbon button. All the non-grid view method just call the BeginInsert method of the grid view which seems to work without issue. I would like to automatically set the inserted row as the selected row of the grid view when the insert is complete. To do this I am using edit complete handler bellow:
private void crashRowEditComplete(object sender, GridViewRowEditEndedEventArgs e) |
{ |
if (e.EditAction == GridViewEditAction.Commit |
&& e.EditOperationType == GridViewEditOperationType.Insert) |
{ |
ApplicationState.Carrier.Crashes.Add((Crash)e.NewData); |
ApplicationState.Carrier.Drivers.Add(((Crash)e.NewData).Driver); |
ApplicationState.Carrier.Vehicles.Add(((Crash)e.NewData).Vehicle); |
crashListGrid.SelectedItem = e.NewData; |
} |
} |
The handler is running fine (checked through debug and the fact that the data does get written out to the file - dependent on the three Add statements), but the item is not getting selected correctly. Instead the first row in the grid always gets selected. This seemed like a pretty simple requirement and I have manipulated the grid selection previously without issue.