DataGrid.GetCellBounds メソッド
セルの四隅を指定する Rectangle を取得します。
オーバーロードの一覧
DataGridCell で指定したセルの Rectangle を取得します。
[Visual Basic] Overloads Public Function GetCellBounds(DataGridCell) As Rectangle
[JScript] public function GetCellBounds(DataGridCell) : Rectangle;
行番号および列番号で指定したセルの Rectangle を取得します。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Function GetCellBounds(Integer, Integer) As Rectangle
[JScript] public function GetCellBounds(int, int) : Rectangle;
使用例
[Visual Basic, C#, C++] GetCellBounds メソッドを使用して、指定したセルの Rectangle を返す例を次に示します。
[Visual Basic, C#, C++] メモ ここでは、GetCellBounds のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。
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++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。