I have a WinForm application with a ultragrid. Via the application there are several ways that a row can be selected: single-clicking it, double-clicking on it, choosing "select" from a right-click menu (context menu), and having it programatically selected by the code based on user actions in other tools and panels.
I need to implement some code that will run everytime a row is selected regardles of how it is selected. is thee some way that I can handle the selection of a row easily so I can put my code in one place?
Thanks!
Steve
Steve,
The sender in this case is going to simply be the grid, so that won't directly help you. What you need to do is:
private void ultraGrid1_AfterSelectChange(object sender, AfterSelectChangeEventArgs e){ UltraGrid grid = (UltraGrid)sender; SelectedRowsCollection rows = grid.Selected.Rows; foreach (UltraGridRow row in rows) { // Do stuff... }}
Naturally if you only allow single selection there will only be one row in the SelectedRowsCollection.
-Matt
Thansk Matt. You IF statement inside of the AfterSelectChanged() method is working. Could you advise on how to get data from the row using this approach?
I tried casting e as an UltraGridRow, and the compiler doesn't like that.
Thanks,
Take a look at the AfterSeletChange event. In here, you can check e.Type to see if it's a row selection (i.e. e.Type == typeof(UltraGridRow))