When the user right clicks on a row, I would like for that row to become the selected row as if the user left clicked the row, for the purpose that the context menu will display options relevant to the selected row.
I have the grid set to single row select by setting:
UltraGrid.DisplayLayout.Override.SelectTypeRow = SelectType.Single;
In order to select the row on a right mouse click I used the MouseDown event:
private void UltraGrid_MouseDown(object sender, MouseEventArgs e){ UltraGridRow row; UIElement element;
if (e.Button == MouseButtons.Right) { element = UltraGrid.DisplayLayout.UIElement.ElementFromPoint(e.Location); row = element.GetContext(typeof(UltraGridRow)) as UltraGridRow; if (row != null && row.IsDataRow) { UltraGrid.ActiveRow = row; } }}
The problem is that sometimes, but not always, the previously selected row stays highlighted seemingly to not unselect, and there are then 2 rows highlighted in the grid. Then once this state starts happening, I can't escape it, there are always 2 rows highlighted. If I sutdown the app and restart, it works fine for awhile but then eventually reverts to its problem state.
Is there a step that I'm missing, or is there an easier way to accomplish what I want?
Thanks!
Bill
Maybe setting the ActiveRow causes the problem? Why not taking the right clicked row from grid.Selected.Rows[0] in the BeforeToolDropdown event?
The problem is that grid.Selected.Rows[0] is the wrong row, it is the old row not the new one. So I am putting myself in a state where the Selected Row and the Active Row are different.
The good news is the by calling grid.Selected.Rows.Clear() before setting the Active seems to solve my problem.
If there is a better way I should have done this, I'd be happy to hear it, but thanks for the help.