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
)

Parameters

row
Type: System::Int32

The number of the cell's row.

col
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 = dynamic_cast<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 = dynamic_cast<CurrencyManager^>(BindingContext[ myDataSet->Tables[ dataGrid1->DataMember ] ]);

         // Get the Rectangle of the clicked cell.
         Rectangle cellRect;
         cellRect = grid->GetCellBounds( hi->Row, hi->Column );

         // Get the clicked DataGridTextBoxColumn.
         DataGridTextBoxColumn^ gridCol = dynamic_cast<DataGridTextBoxColumn^>(dgt->GridColumnStyles[ hi->Column ]);

         // Insert code to edit the value.
      }
   }

.NET Framework
Available since 1.1
Return to top
Show: