Articles in this section
Category / Section

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

1 min read

Position of current cell

To retrieve the co-ordinates 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 co-ordinates like Top, Left, Height and Width.

C#

//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());
}

VB

'Hook the MouseClick event to find the co-ordinates of the current cell.
Private 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

Samples:

C#: CurrentCellPosition

VB: CurrentCellPosition

 

Conclusion

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

You can refer to WinForms Grid control feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms Grid control example to understand how to create and manipulate data.

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 forumsDirect-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)
Please sign in to leave a comment
Access denied
Access denied