次の方法で共有


DataGrid.GetCellBounds メソッド (Int32, Int32)

行番号および列番号で指定したセルの Rectangle を取得します。

Overloads Public Function GetCellBounds( _
   ByVal row As Integer, _   ByVal col As Integer _) As Rectangle
[C#]
public Rectangle GetCellBounds(introw,intcol);
[C++]
public: Rectangle GetCellBounds(introw,intcol);
[JScript]
public function GetCellBounds(
   row : int,col : int) : Rectangle;

パラメータ

  • row
    セルの行の番号。
  • col
    セルの列の番号。

戻り値

現在のセルの四隅を定義する Rectangle

使用例

[Visual Basic, C#, C++] GetCellBounds メソッドを使用して、指定したセルの Rectangle を返す例を次に示します。

 
Protected Sub dataGrid1_MouseDown _
(sender As Object, e As MouseEventArgs)
   ' Use the HitTest method to get a HitTestInfo object.
   Dim hi As System.Windows.Forms.DataGrid.HitTestInfo
   Dim grid As DataGrid = CType(sender, DataGrid)
   hi = grid.HitTest(e.X, e.Y)
   ' Test if the clicked area was a cell.
   If hi.Type = DataGrid.HitTestType.Cell Then
   ' If it's a cell, get the GridTable and CurrencyManager of the
   ' clicked table.         
   Dim dgt As DataGridTableStyle = dataGrid1.TableStyles(0)
   Dim myCurrencyManager As CurrencyManager = _
   CType(Me.BindingContext _
   (myDataSet.Tables(dataGrid1.DataMember)), CurrencyManager)
   ' Get the Rectangle of the clicked cell.
   Dim cellRect As Rectangle
   cellRect = grid.GetCellBounds(hi.Row, hi.Column)
   ' Get the clicked DataGridTextBoxColumn.
   Dim gridCol As DataGridTextBoxColumn = _
   CType(dgt.GridColumnStyles(hi.Column), DataGridTextBoxColumn)
      ' Insert code to dit the value.
   End If
End Sub 

[C#] 
protected 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 = 
      (CurrencyManager)this.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 =
      (DataGridTextBoxColumn) dgt.GridColumnStyles[hi.Column];
      // Insert code to edit the value.
      
   }
}


[C++] 
protected:
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->Item[0];     
      CurrencyManager* myCurrencyManager = 
        dynamic_cast<CurrencyManager*>(BindingContext->Item[myDataSet->Tables->Item[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->Item[hi->Column]);
      // Insert code to edit the value.
      
   }
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

DataGrid クラス | DataGrid メンバ | System.Windows.Forms 名前空間 | DataGrid.GetCellBounds オーバーロードの一覧 | GetCurrentCellBounds | CurrentCell