Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
245
Right Mouse Click Row Select
posted

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

 

 

Parents
  • 17259
    Offline posted

    Maybe setting the ActiveRow causes the problem? Why not taking the right clicked row from grid.Selected.Rows[0] in the BeforeToolDropdown event?

Reply Children