Articles in this section
Category / Section

How to get the coordinates of current cell in WinForms GridControl?

Position of current cell


To retrieve the coordinates of the current cell in WinForms GridControl, you can use the RangeInfoToRectangle method. It converts the RangeInfo of the current cell to a rectangle-like object. Using this rectangle, you can get the coordinates like Top, Left, Height and Width.

//Hook the MouseClick event to find the co-ordinates of the current cell.
this.gridControl1.MouseClick += gridControl1_MouseClick;

void gridControl1_MouseClick(object sender, MouseEventArgs e)
{
    //Get CurrentCell from Grid.
    GridCurrentCell cc = this.gridControl1.CurrentCell;

    //Get the rectangular RangeInfo of CurrentCell.
    Rectangle cellRect = this.gridControl1.RangeInfoToRectangle(GridRangeInfo.Cell(cc.RowIndex, cc.ColIndex));

    //Display the coordinates of the CurrentCell.
    MessageBox.Show(cellRect.ToString());
}
'Hook the MouseClick event to find the co-ordinates of the current cell.
AddHandler Me.gridControl1.MouseClick,  AddressOf gridControl1_MouseClick

Private Sub gridControl1_MouseClick(ByVal sender As Object, ByVal e As MouseEventArgs)
    'Get CurrentCell from Grid.
    Dim cc As GridCurrentCell = Me.gridControl1.CurrentCell

    'Get the rectangular RangeInfo of CurrentCell.
    Dim cellRect As Rectangle = Me.gridControl1.RangeInfoToRectangle(GridRangeInfo.Cell(cc.RowIndex, cc.ColIndex))

    'Display the coordinates of the CurrentCell.
    MessageBox.Show(cellRect.ToString())
End Sub

The following screenshot displays the coordinates of the CurrentCell.

Show the current cell position


   Figure
1: Output

Conclusion

I hope you enjoyed learning how to get the coordinates of the current cell in the WinForms GridControl.


You can refer to our WinForms GridControl feature tour page to know about its other groundbreaking feature representations and WinForms GridControl documentation, and how to quickly get started for configuration specifications.


For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.


If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied