我想累积对数据网格视图点击所做的点击次数,但我总是获得1次点击
Private Sub ClickMouse(sender As Object, e As DataGridViewCellMouseEventArgs) Handles LRInc.CellMouseClick
MsgBox(e.Clicks & e.ColumnIndex & e.RowIndex)
End Sub
答案 0 :(得分:0)
在 DataGridView
中使用 OnMouseDown 事件private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Clicks == 1)
{
// Single Click occurred.
label1.Text="Single Click";
}
if (e.Clicks == 2)
{
// Double Click occurred.
label1.Text = "Double Click";
}
}
答案 1 :(得分:0)
MessageBox
并忽略其他点击。您需要实现另一种方法来显示结果。
Private Sub ClickMouse(sender As Object, e As DataGridViewCellMouseEventArgs) Handles datagridview.CellMouseClick
System.Diagnostics.Debug.Print(e.Clicks & e.ColumnIndex & e.RowIndex)
End Sub
结果应该在“输出”窗口中。
或者,您可以创建一个TextBox(Text1
)来保存结果
Private Sub ClickMouse(sender As Object, e As DataGridViewCellMouseEventArgs) Handles datagridview.CellMouseClick
Text1.text = e.Clicks & e.ColumnIndex & e.RowIndex
End Sub
编辑 - 积累
声明和初始化:
Private Accums As New ArrayList
事件:
Private Sub ClickMouse(sender As Object, e As DataGridViewCellMouseEventArgs) Handles datagridview.CellMouseClick
Accums.Add(New Integer() {e.Clicks, e.ColumnIndex, e.RowIndex})
End Sub