Sometimes, working with the infragistics wingrid can be a PITA! Take, for example, the act of making the current row active upon right click before the context menu is displayed.
You'd think they'd have a HitTest method or something similar, but they don't. Well, they do, but that's on an UltraGridRow.AccessibleObject or something like that--totally useless for what I need to do. First, I look in help. Yup, nothing there. So I jump out to devcenter.infragistics.com and it's my lucky day, they have an article (http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=8483) featuring how to make stuff happen when you right click on a wingrid. Must be something they get asked quite frequently.
So, I follow the steps there and enter the following code:
Point mousePoint =
new Point(e.X,e.Y);
UIElement element = ((UltraGrid)sender).DisplayLayout.UIElement.ElementFromPoint(mousePoint);
UltraGridCell cell = element.GetContext(
typeof(UltraGridCell)) as UltraGridCell;
if (cell!= null)
{
cell.Row.Selected=
true;
}
This ALMOST works, but not quite. When you right click, the row you were on remains highlighted. To make it work as expected, you have to reset the active row. Here's the final code:
private void gridRecentSignups_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
Point mousePoint =
new Point(e.X,e.Y);
UIElement element = ((UltraGrid)sender).DisplayLayout.UIElement.ElementFromPoint(mousePoint);
UltraGridCell cell = element.GetContext(
typeof(UltraGridCell)) as UltraGridCell;
if (cell!= null)
{
gridRecentSignups.ActiveRow=cell.Row;
cell.Row.Selected=
true;
}
}
The Cell.Row.Selected may not be needed, but just in case, I left it in. Oh what fun.