I have a bound grid with an unbound column. The unbound column has a dropdown associated with it, and I would like to run some code immediately when the user selects a new item from that dropdown.
The code that runs potentially causes all the grids on the form to be rebound with new values.
The user should not be required to click onto a new row before the event fires (particularly as there is currently only 1 row in the grid, so you have to click on an entirely different tab before those types of event are fired).
I have tried the following events so far:
AfterRowUpdate - fires too late (when you click on a new tab)
AfterExitEditMode - no information about which grid the event is firing for (the grids are dynamically generated at run-time and share a single event handler)
BeforeCellUpdate - get an InvalidOperationException when the grid is rebound because the BeforeCellUpdate event is still running, even if you cancel the update
CellChange - cell.Value and cell.ValueList.SelectedItemIndex show the old value, not the new one - fires too early?
AfterCellUpdate - fires too late (when you click on a new tab)
Any recommendations as to which event is best to use? Thanks!
Hi,
I would use CellChange. The trick is that you have to use the cell's Text property, because the Value isn't updated at this point.
If you need to find take the Text and find the matching Value in the list, you can do this:
private void ultraGrid1_CellChange(object sender, CellEventArgs e) { UltraGridCell cell = e.Cell; UltraGridColumn column = cell.Column; if (column.Key == "MyUnboundColumn") { string cellText = cell.Text; int index = -1; object value = cell.ValueList.GetValue(cellText, ref index); if (index >= 0) Debug.WriteLine(value); else Debug.WriteLine("Text does not match any value on the list."); } }
thanks mike, it solved my problem.