DataGridViewCellMouseEventArgs 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
每当鼠标在 DataGridView 内移动时,都会为 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
- 继承
示例
以下代码示例演示了此类型的用法。
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) |