DataGridViewCellMouseEventArgs 類別

定義

提供每當滑鼠移至 DataGridView 內部時由 DataGridViewCell 所引發之滑鼠事件 (Mouse Event) 的資料。Provides data for mouse events raised by a DataGridView whenever the mouse is moved within a 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
繼承
DataGridViewCellMouseEventArgs

範例

下列程式碼範例說明如何使用此類型。The following code example illustrates the use of this type.

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

備註

類別會提供下列DataGridView事件的資料: DataGridViewCellMouseEventArgsThe DataGridViewCellMouseEventArgs class provides data for the following DataGridView events:

建構函式

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

初始化 DataGridViewCellMouseEventArgs 類別的新執行個體。Initializes a new instance of the DataGridViewCellMouseEventArgs class.

屬性

Button

取得按下哪個滑鼠鍵的資訊。Gets which mouse button was pressed.

(繼承來源 MouseEventArgs)
Clicks

取得按下並釋放滑鼠鍵的次數。Gets the number of times the mouse button was pressed and released.

(繼承來源 MouseEventArgs)
ColumnIndex

取得儲存格之以零起始的資料行索引。Gets the zero-based column index of the cell.

Delta

取得滑鼠滾輪滾動時帶有正負號的刻度數乘以 WHEEL_DELTA 常數。Gets a signed count of the number of detents the mouse wheel has rotated, multiplied by the WHEEL_DELTA constant. 一個刻度是一個滑鼠滾輪的刻痕。A detent is one notch of the mouse wheel.

(繼承來源 MouseEventArgs)
Location

取得滑鼠在產生滑鼠事件期間的位置。Gets the location of the mouse during the generating mouse event.

(繼承來源 MouseEventArgs)
RowIndex

取得儲存格之以零起始的資料列索引。Gets the zero-based row index of the cell.

X

取得滑鼠在產生滑鼠事件期間的 X 座標。Gets the x-coordinate of the mouse during the generating mouse event.

(繼承來源 MouseEventArgs)
Y

取得滑鼠在產生滑鼠事件期間的 Y 座標。Gets the y-coordinate of the mouse during the generating mouse event.

(繼承來源 MouseEventArgs)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

作為預設雜湊函數。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

適用於

另請參閱