The Life and Times of a Dev

Yes, we're really that weird
posts - 179, comments - 302, trackbacks - 106

My Links

News

Twitter









Tag Cloud

Archives

Post Categories

Play

Work

Infragistics and the WinGrid

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.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Print | posted on Tuesday, December 20, 2005 1:39 PM | Filed Under [ Work ]

Feedback

Gravatar

# re: Infragistics and the WinGrid

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.
12/20/2005 1:58 PM | Anthony Trudeau
Gravatar

# re: Infragistics and the WinGrid

I used multiselectionmode for selecting multiple cell but how do i get back the selected cell data in collection
8/13/2006 11:49 PM | Kapil Dalvi
Gravatar

# re: Infragistics and the WinGrid

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!
4/25/2008 2:32 PM | MarkC
Gravatar

# re: Infragistics and the WinGrid

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
5/2/2008 5:41 AM | aussiegaz
Gravatar

# re: Infragistics and the WinGrid

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
6/30/2010 12:12 PM | N_L_S
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: