Determine WinGrid Mouse Position and Cell Identification

Jason Beres [Infragistics] / Saturday, February 28, 2009

Many projects using the WinGrid for navigation need to be able to determine which cell the user clicked on without the cell being selected or becoming active.  Using the grid's MouseUp or MouseDown events, you can retrieve a reference to the UIElement for the mouse point, retrieve a reference to the Cell, and if the Cell reference is not Nothing display the Band and Column Key.

Dim aUIElement As Infragistics.Win.UIElement
aUIElement = CustomersUltraGrid.DisplayLayout.UIElement.ElementFromPoint( _
New Point(e.X, e.Y))
' declare and retrieve a reference to the Cell
Dim aCell As UltraGridCell
aCell = aUIElement.GetContext( _
        GetType(Infragistics.Win.UltraWinGrid.UltraGridCell))
' if a cell was found display the band and column key
If Not aCell Is Nothing Then

    txtBand.Text = aCell.Band.Index.ToString
    txtColumn.Text = aCell.Column.Key

Else
    txtBand.Text = ""
    txtColumn.Text = ""

End If

You can use similar code to access the Column:

' retrieve the Column from the UIElement
Dim mouseupColumn As UltraGridColumn _
= mouseupUIElement.GetContext(GetType(UltraGridColumn))