DataGridViewCellMouseEventArgs Klasa

Definicja

Udostępnia dane dotyczące zdarzeń myszy zgłaszanych za DataGridView każdym razem, gdy mysz zostanie przeniesiona w obiekcie DataGridViewCell.

public ref class DataGridViewCellMouseEventArgs : System::Windows::Forms::MouseEventArgs
public class DataGridViewCellMouseEventArgs : System.Windows.Forms.MouseEventArgs
type DataGridViewCellMouseEventArgs = class
    inherit MouseEventArgs
Public Class DataGridViewCellMouseEventArgs
Inherits MouseEventArgs
Dziedziczenie
DataGridViewCellMouseEventArgs

Przykłady

Poniższy przykład kodu ilustruje użycie tego typu.

private void dataGridView1_ColumnHeaderMouseClick(
    object sender, DataGridViewCellMouseEventArgs e)
{
    DataGridViewColumn newColumn = dataGridView1.Columns[e.ColumnIndex];
    DataGridViewColumn oldColumn = dataGridView1.SortedColumn;
    ListSortDirection direction;

    // If oldColumn is null, then the DataGridView is not sorted.
    if (oldColumn != null)
    {
        // Sort the same column again, reversing the SortOrder.
        if (oldColumn == newColumn &&
            dataGridView1.SortOrder == SortOrder.Ascending)
        {
            direction = ListSortDirection.Descending;
        }
        else
        {
            // Sort a new column and remove the old SortGlyph.
            direction = ListSortDirection.Ascending;
            oldColumn.HeaderCell.SortGlyphDirection = SortOrder.None;
        }
    }
    else
    {
        direction = ListSortDirection.Ascending;
    }

    // Sort the selected column.
    dataGridView1.Sort(newColumn, direction);
    newColumn.HeaderCell.SortGlyphDirection =
        direction == ListSortDirection.Ascending ?
        SortOrder.Ascending : SortOrder.Descending;
}

private void dataGridView1_DataBindingComplete(object sender,
    DataGridViewBindingCompleteEventArgs e)
{
    // Put each of the columns into programmatic sort mode.
    foreach (DataGridViewColumn column in dataGridView1.Columns)
    {
        column.SortMode = DataGridViewColumnSortMode.Programmatic;
    }
}
Private Sub dataGridView1_ColumnHeaderMouseClick(ByVal sender As Object, _
    ByVal e As DataGridViewCellMouseEventArgs) _
    Handles dataGridView1.ColumnHeaderMouseClick

    Dim newColumn As DataGridViewColumn = _
        dataGridView1.Columns(e.ColumnIndex)
    Dim oldColumn As DataGridViewColumn = dataGridView1.SortedColumn
    Dim direction As ListSortDirection

    ' If oldColumn is null, then the DataGridView is not currently sorted.
    If oldColumn IsNot Nothing Then

        ' Sort the same column again, reversing the SortOrder.
        If oldColumn Is newColumn AndAlso dataGridView1.SortOrder = _
            SortOrder.Ascending Then
            direction = ListSortDirection.Descending
        Else

            ' Sort a new column and remove the old SortGlyph.
            direction = ListSortDirection.Ascending
            oldColumn.HeaderCell.SortGlyphDirection = SortOrder.None
        End If
    Else
        direction = ListSortDirection.Ascending
    End If

    ' Sort the selected column.
    dataGridView1.Sort(newColumn, direction)
    If direction = ListSortDirection.Ascending Then
        newColumn.HeaderCell.SortGlyphDirection = SortOrder.Ascending
    Else
        newColumn.HeaderCell.SortGlyphDirection = SortOrder.Descending
    End If

End Sub

Private Sub dataGridView1_DataBindingComplete(ByVal sender As Object, _
    ByVal e As DataGridViewBindingCompleteEventArgs) _
    Handles dataGridView1.DataBindingComplete

    ' Put each of the columns into programmatic sort mode.
    For Each column As DataGridViewColumn In dataGridView1.Columns
        column.SortMode = DataGridViewColumnSortMode.Programmatic
    Next
End Sub

Uwagi

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

Konstruktory

DataGridViewCellMouseEventArgs(Int32, Int32, Int32, Int32, MouseEventArgs)

Inicjuje nowe wystąpienie klasy DataGridViewCellMouseEventArgs.

Właściwości

Button

Pobiera, który przycisk myszy został naciśnięty.

(Odziedziczone po MouseEventArgs)
Clicks

Pobiera liczbę naciśnięcia i zwolnienia przycisku myszy.

(Odziedziczone po MouseEventArgs)
ColumnIndex

Pobiera indeks kolumny zerowej komórki.

Delta

Pobiera podpisaną liczbę odcięć obróconych kółko myszy, mnożone przez stałą WHEEL_DELTA. Zacięcie jest jednym nacięciem kółka myszy.

(Odziedziczone po MouseEventArgs)
Location

Pobiera lokalizację myszy podczas generowania zdarzenia myszy.

(Odziedziczone po MouseEventArgs)
RowIndex

Pobiera zerowy indeks wiersza komórki.

X

Pobiera współrzędną x myszy podczas generowania zdarzenia myszy.

(Odziedziczone po MouseEventArgs)
Y

Pobiera współrzędną y myszy podczas generowania zdarzenia myszy.

(Odziedziczone po MouseEventArgs)

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ż