ユーザーがクリックした列の番号を取得します。
Public ReadOnly Property Column As Integer
[C#]
public int Column {get;}
[C++]
public: __property int get_Column();
[JScript]
public function get Column() : int;
プロパティ値
列の番号。
解説
座標がセルの外部にある場合、このプロパティは -1 を返します。
使用例
[Visual Basic, C#, C++] System.Windows.Forms.DataGrid コントロールの MouseDown イベント内から HitTest メソッドを呼び出すことにより、クリックされた行と列の番号を出力する例を次に示します。この例では、 DataGrid.HitTestInfo オブジェクトが返されます。
Protected Sub dataGrid1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs)
Dim newLine As String = ControlChars.Cr
Console.WriteLine(newLine)
Dim myHitTest As System.Windows.Forms.DataGrid.HitTestInfo
' Use the DataGrid control's HitTest method with
' the x and y properties.
myHitTest = dataGrid1.HitTest(e.X, e.Y)
Console.WriteLine(("Column " & myHitTest.Column))
Console.WriteLine(("Row " & myHitTest.Row))
End Sub 'dataGrid1_MouseDown
[C#]
protected void dataGrid1_MouseDown
(object sender, System.Windows.Forms.MouseEventArgs e)
{
string newLine = "\n";
Console.WriteLine(newLine);
System.Windows.Forms.DataGrid.HitTestInfo myHitTest;
/* Use the DataGrid control's HitTest method with
the x and y properties. */
myHitTest = dataGrid1.HitTest(e.X,e.Y);
Console.WriteLine("Column " + myHitTest.Column);
Console.WriteLine("Row " + myHitTest.Row);
}
[C++]
protected:
void dataGrid1_MouseDown(Object* /*sender*/, System::Windows::Forms::MouseEventArgs* e)
{
String* newLine = S"\n";
Console::WriteLine(newLine);
System::Windows::Forms::DataGrid::HitTestInfo* myHitTest;
/* Use the DataGrid control's HitTest method with
the x and y properties. */
myHitTest = dataGrid1->HitTest(e->X,e->Y);
Console::WriteLine(S"Column {0}", __box(myHitTest->Column));
Console::WriteLine(S"Row {0}", __box(myHitTest->Row));
}
[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.HitTestInfo クラス | DataGrid.HitTestInfo メンバ | System.Windows.Forms 名前空間 | DataGrid | DataGrid.HitTestType | HitTest