共用方式為


DataGridViewCellMouseEventArgs 類別

定義

提供每當滑鼠移至 DataGridView 內部時由 DataGridViewCell 所引發之滑鼠事件 (Mouse Event) 的資料。

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
繼承
DataGridViewCellMouseEventArgs

範例

下列程式碼範例說明如何使用此類型。

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

備註

類別 DataGridViewCellMouseEventArgs 提供下列 DataGridView 事件的資料:

建構函式

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

初始化 DataGridViewCellMouseEventArgs 類別的新執行個體。

屬性

Button

取得按下哪個滑鼠鍵的資訊。

(繼承來源 MouseEventArgs)
Clicks

取得按下並釋放滑鼠鍵的次數。

(繼承來源 MouseEventArgs)
ColumnIndex

取得儲存格之以零起始的資料行索引。

Delta

取得滑鼠滾輪滾動時帶有正負號的刻度數乘以 WHEEL_DELTA 常數。 一個刻度是一個滑鼠滾輪的刻痕。

(繼承來源 MouseEventArgs)
Location

取得滑鼠在產生滑鼠事件期間的位置。

(繼承來源 MouseEventArgs)
RowIndex

取得儲存格之以零起始的資料列索引。

X

取得滑鼠在產生滑鼠事件期間的 X 座標。

(繼承來源 MouseEventArgs)
Y

取得滑鼠在產生滑鼠事件期間的 Y 座標。

(繼承來源 MouseEventArgs)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱