I’ve been working with Infragistics tools, specifically the UltraWinGrid for 10 years or more (worked with the Sheridan grid before that, anyone remember those tools?), and outside of the Infragistics forums there seems to be very little in the way of information on this very powerful and complex tool. Perhaps I can leverage my experiences with these tools into a nice little series of posts on things I’ve discovered over the years.
I came upon a situation where I wanted to right click on a grid, have it select the row under the mouse and bring up a context menu to act on that selected row. As another requirement I wanted it to only act upon data rows.
I came up with the following extension method.
- First get the element under the mouse and determine if it’s a row element.
- If it’s a row, is it a datarow?
- Make it the active row.
- if the row is not already selected, select it and deselect any other row.
- if the row is already selected, then do nothing else special with the selection properties.
- if we’ve clicked somewhere not a datarow, I clear any selected rows in the grid.
Then to use this, I simply call it in the MouseDown event on the grid as follows.
1 privatevoid grdLabsMouseDown(object sender, MouseEventArgs e)
3 if (e.Button == MouseButtons.Right)
Pretty basic really, but knowing how to determine what element is under the mouse is a critical tool in your belt when dealing with the WinGrid and opens up the door for a lot of advanced features.