DataGridViewCellEventArgs Klasa

Definicja

Udostępnia dane dotyczące DataGridView zdarzeń związanych z operacjami komórek i wierszy.

public ref class DataGridViewCellEventArgs : EventArgs
public class DataGridViewCellEventArgs : EventArgs
type DataGridViewCellEventArgs = class
    inherit EventArgs
Public Class DataGridViewCellEventArgs
Inherits EventArgs
Dziedziczenie
DataGridViewCellEventArgs
Pochodne

Przykłady

W poniższym przykładzie kodu pokazano, jak używać programów obsługi zdarzeń CellMouseEnter i CellMouseLeave określić, czy można kliknąć komórkę. Przykład aktualizuje każdą ToolTipText wartość właściwości, aby anonsować bieżący układ obrazu. Ten kod jest częścią większego przykładu pokazanego w temacie How to: Work with Image Columns in the Windows Forms DataGridView Control (Jak pracować z kolumnami obrazów w kontrolce DataGridView).

void dataGridView1_CellMouseEnter( Object^ sender, DataGridViewCellEventArgs^ e )
{
   Bitmap^ markingUnderMouse = dynamic_cast<Bitmap^>(dataGridView1->Rows[ e->RowIndex ]->Cells[ e->ColumnIndex ]->Value);
   if ( markingUnderMouse == blank )
   {
      dataGridView1->Cursor = Cursors::Default;
   }
   else
   if ( markingUnderMouse == o || markingUnderMouse == x )
   {
      dataGridView1->Cursor = Cursors::No;
      ToolTip(e,true);
   }
}

void ToolTip( DataGridViewCellEventArgs^ e, bool showTip )
{
   DataGridViewImageCell^ cell = dynamic_cast<DataGridViewImageCell^>(dataGridView1->Rows[ e->RowIndex ]->Cells[ e->ColumnIndex ]);
   DataGridViewImageColumn^ imageColumn = dynamic_cast<DataGridViewImageColumn^>(dataGridView1->Columns[ cell->ColumnIndex ]);
   if ( showTip )
         cell->ToolTipText = imageColumn->Description;
   else
   {
      cell->ToolTipText = String::Empty;
   }
}

void dataGridView1_CellMouseLeave( Object^ sender, DataGridViewCellEventArgs^ e )
{
   ToolTip( e, false );
   dataGridView1->Cursor = Cursors::Default;
}
private void dataGridView1_CellMouseEnter(object sender,
    DataGridViewCellEventArgs e)
{
    Bitmap markingUnderMouse = (Bitmap)dataGridView1.
           Rows[e.RowIndex].
           Cells[e.ColumnIndex].Value;

    if (markingUnderMouse == blank)
    {
        dataGridView1.Cursor = Cursors.Default;
    }
    else if (markingUnderMouse == o || markingUnderMouse == x)
    {
        dataGridView1.Cursor = Cursors.No;
        ToolTip(e, true);
    }
}

private void ToolTip(DataGridViewCellEventArgs e, bool showTip)
{
    DataGridViewImageCell cell = (DataGridViewImageCell)
        dataGridView1
        .Rows[e.RowIndex].Cells[e.ColumnIndex];
    DataGridViewImageColumn imageColumn =
        (DataGridViewImageColumn)
        dataGridView1.Columns[cell.ColumnIndex];

    if (showTip)
    {
        cell.ToolTipText = imageColumn.Description;
    }
    else { cell.ToolTipText = String.Empty; }
}

private void dataGridView1_CellMouseLeave(object sender,
    DataGridViewCellEventArgs e)
{
    ToolTip(e, false);
    dataGridView1.Cursor = Cursors.Default;
}
Private Sub dataGridView1_CellMouseEnter(ByVal sender As Object, _
    ByVal e As DataGridViewCellEventArgs) _
    Handles dataGridView1.CellMouseEnter

    Dim markingUnderMouse As Bitmap = _
        CType(dataGridView1.Rows(e.RowIndex). _
            Cells(e.ColumnIndex).Value, Bitmap)

    If markingUnderMouse Is blank Then
        dataGridView1.Cursor = Cursors.Default
    ElseIf markingUnderMouse Is o OrElse markingUnderMouse Is x Then
        dataGridView1.Cursor = Cursors.No
        ToolTip(e)
    End If
End Sub

Private Sub ToolTip( _
    ByVal e As DataGridViewCellEventArgs)

    Dim cell As DataGridViewImageCell = _
        CType(dataGridView1.Rows(e.RowIndex). _
        Cells(e.ColumnIndex), DataGridViewImageCell)
    Dim imageColumn As DataGridViewImageColumn = _
        CType(dataGridView1.Columns(cell.ColumnIndex), _
        DataGridViewImageColumn)

    cell.ToolTipText = imageColumn.Description
End Sub

Private Sub dataGridView1_CellMouseLeave(ByVal sender As Object, _
    ByVal e As DataGridViewCellEventArgs) _
    Handles dataGridView1.CellMouseLeave

    dataGridView1.Cursor = Cursors.Default
End Sub

Uwagi

Klasa DataGridViewCellEventArgs udostępnia dane dla następujących DataGridView zdarzeń:

Konstruktory

DataGridViewCellEventArgs(Int32, Int32)

Inicjuje nowe wystąpienie klasy DataGridViewCellEventArgs.

Właściwości

ColumnIndex

Pobiera wartość wskazującą indeks kolumn komórki, dla którego występuje zdarzenie.

RowIndex

Pobiera wartość wskazującą indeks wiersza komórki, dla którego występuje zdarzenie.

Metody

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera bieżące wystąpienie.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Dotyczy

Zobacz też