Geeks With Blogs

The Life and Times of a Dev Yes, we're really that weird

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.

Posted on Tuesday, December 20, 2005 1:39 PM Work | Back to top


Comments on this post: Infragistics and the WinGrid

# re: Infragistics and the WinGrid
Requesting Gravatar...
I agree that working with the Infragistics API can be a pain. However, there's a lot of power there that is nice to know is there. It only seems like I appreciate it when I have to do something special using the standard datagrid or other control for some reason. Talk about a pain.
Left by Anthony Trudeau on Dec 20, 2005 1:58 PM

# re: Infragistics and the WinGrid
Requesting Gravatar...
I used multiselectionmode for selecting multiple cell but how do i get back the selected cell data in collection
Left by Kapil Dalvi on Aug 13, 2006 11:49 PM

# re: Infragistics and the WinGrid
Requesting Gravatar...
Sometimes?? LOL..y thr r many painz, stupid ones too, but as pointed out, the alternatives are quite ugly :). Thanks for the info it has helped me gr8ly!
Left by MarkC on Apr 25, 2008 2:32 PM

# re: Infragistics and the WinGrid
Requesting Gravatar...
Same goes with the rest of their components e.g. UltraExplorerBar

UIElement element = ultraExplorerBar1.UIElement.ElementFromPoint(e.Location);

UltraExplorerBarItem item =
element.GetContext(typeof(UltraExplorerBarItem)) as UltraExplorerBarItem;

if (item != null)
{
ultraExplorerBar1.ActiveGroup = item.Group;
ultraExplorerBar1.ActiveItem = item;
item.Checked = true;
}

I know the original comment was made a few years ago but its still a problem
Left by aussiegaz on May 02, 2008 5:41 AM

# re: Infragistics and the WinGrid
Requesting Gravatar...
The code above didn't entirely work for me I had to add

grdAuditQuery.Selected.Rows.Clear()

Here is the rest of the code for vb.net

Dim mousePoint As Point = New Point(e.X, e.Y)

Dim element As UIElement = DirectCast(sender, UltraGrid).DisplayLayout.UIElement.ElementFromPoint(mousePoint)

Dim cell As UltraGridCell = TryCast(element.GetContext(GetType(UltraGridCell)), UltraGridCell)

grdAuditQuery.Selected.Rows.Clear()

If Not cell Is Nothing Then

grdAuditQuery.ActiveRow = cell.Row
cell.Row.Selected = True

End If
Left by N_L_S on Jun 30, 2010 12:12 PM

Your comment:
 (will show your gravatar)


Copyright © Robert May | Powered by: GeeksWithBlogs.net