如何创建变量以累积通过datagridview进行的点击?

时间:2013-05-18 18:57:54

标签: vb.net datagridview click

我想累积对数据网格视图点击所做的点击次数,但我总是获得1次点击

    Private Sub ClickMouse(sender As Object, e As DataGridViewCellMouseEventArgs) Handles LRInc.CellMouseClick
    MsgBox(e.Clicks & e.ColumnIndex & e.RowIndex)
End Sub

2 个答案:

答案 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