【问题标题】:CellClick event: Selection from combo-box not smoothCellClick 事件:从组合框中的选择不平滑
【发布时间】:2012-05-28 13:38:25
【问题描述】:

我有一个有两列的DataGridView。一个是DataGridViewComboBoxColumn,另一个是DataGridViewButtonColumn。为了从DataGridViewButtonColumn 捕获按钮单击,我编写了CellClick 事件,它工作正常。但是,这并不是我从DataGridViewComboBoxColumn 'smooth' 中做出的选择。我的意思是我必须单击组合框两次才能显示下拉列表。我注意到每次点击都会触发CellClick。但只有在第二次单击后才会弹出下拉菜单。解决方法是什么?

【问题讨论】:

    标签: .net vb.net winforms events datagridview


    【解决方案1】:

    问题已通过将DataGridViewEditMode 属性设置为EditOnEnter 来解决,如下所述:http://social.msdn.microsoft.com/forums/en-US/winformsdatacontrols/thread/c461b774-ece5-4fdd-86c5-90e5b6426690/

    【讨论】:

      【解决方案2】:

      我发现最好的解决方法是在鼠标移到当前行时保持选中状态,以防止多次单击,一个是将焦点带到当前行,第二个是选择组合框下拉列表,添加以下内容datagrid的鼠标移动事件代码:

          Private Sub DataGridView1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseMove
          Dim theRow As Integer = DataGridView1.HitTest(e.X, e.Y).RowIndex
          If theRow < 0 Then
              Exit Sub
          End If
          Me.DataGridView1.CurrentCell = Me.DataGridView1.Rows(theRow).Cells(0)
      End Sub
      

      【讨论】:

      • 它仍然无法正常工作。我仍然需要在组合框上单击两次才能显示下拉菜单。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-01
      • 2023-01-14
      • 1970-01-01
      • 1970-01-01
      • 2019-09-24
      • 2013-12-04
      相关资源
      最近更新 更多