DataGrid.HitTestInfo.Column Proprietà

Definizione

Ottiene il numero della colonna su cui l'utente ha fatto clic.

public:
 property int Column { int get(); };
public int Column { get; }
member this.Column : int
Public ReadOnly Property Column As Integer

Valore della proprietà

Il numero della colonna.

Esempio

Nell'esempio seguente vengono stampati i numeri della riga e della colonna su cui è stato fatto clic chiamando il HitTest metodo dall'interno dell'evento MouseDown di un System.Windows.Forms.DataGrid controllo . Questa operazione restituisce un oggetto DataGrid.HitTestInfo.

private:
   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 {0}", myHitTest->Column );
      Console::WriteLine( "Row {0}", myHitTest->Row );
   }
private 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);
}
Private Sub dataGrid1_MouseDown(ByVal sender As Object, ByVal 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

Commenti

Se la coordinata non è una cella, la proprietà restituisce -1.

Si applica a

Vedi anche