Export (0) Print
Expand All

DataGrid.GetCellBounds Method (Int32, Int32)

Gets the Rectangle of the cell specified by row and column number.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public Rectangle GetCellBounds(
	int row,
	int col


Type: System.Int32

The number of the cell's row.

Type: System.Int32

The number of the cell's column.

Return Value

Type: System.Drawing.Rectangle
A Rectangle that defines the current cell's corners.

To retrieve the cell bounds for the currently selected cell, use GetCurrentCellBounds.

The following code example uses the GetCellBounds method to return a Rectangle of a specified cell.

private void dataGrid1_MouseDown(object sender, MouseEventArgs e){
   // Use the HitTest method to get a HitTestInfo object.
   System.Windows.Forms.DataGrid.HitTestInfo hi;   
   DataGrid grid = (DataGrid) sender;
   hi=grid.HitTest(e.X, e.Y);
   // Test if the clicked area was a cell. 
   if(hi.Type==DataGrid.HitTestType.Cell ) {
      // If it's a cell, get the GridTable and CurrencyManager of the 
      // clicked table.         
      DataGridTableStyle dgt = dataGrid1.TableStyles[0];     
      CurrencyManager myCurrencyManager = 
      // Get the Rectangle of the clicked cell.
      Rectangle cellRect;
      cellRect=grid.GetCellBounds(hi.Row, hi.Column);
      // Get the clicked DataGridTextBoxColumn.
      DataGridTextBoxColumn gridCol =
      (DataGridTextBoxColumn) dgt.GridColumnStyles[hi.Column];
      // Insert code to edit the value.


.NET Framework

Supported in: 4.6, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft