VB / C# - 单击下拉列表时ComboBox更改值 - bug

时间:2017-10-11 09:05:29

标签: c# vb.net visual-studio

我有一个DataGridViewComboBoxColumn并且运行良好。

我也绑定了两个事件。

一个用于检测选择更改,另一个用于一次点击下拉

给定是检测选择变化:

  Private Sub DataGridView2Rachunek_EditingControlShowing(ByVal sender As System.Object, ByVal e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView2Rachunek.EditingControlShowing
        ' Only for a DatagridComboBoxColumn at ColumnIndex 1.
        If DataGridView2Rachunek.CurrentCell.ColumnIndex = DataGridView2Rachunek.Columns("Stan").Index Then
            Dim combo As ComboBox = CType(e.Control, ComboBox)
            If (combo IsNot Nothing) Then
                ' Remove an existing event-handler, if present, to avoid 
                ' adding multiple handlers when the editing control is reused.
                RemoveHandler combo.SelectionChangeCommitted, New EventHandler(AddressOf ComboBox_SelectionChangeCommitted)

                ' Add the event handler. 
                AddHandler combo.SelectionChangeCommitted, New EventHandler(AddressOf ComboBox_SelectionChangeCommitted)
            End If
        End If
    End Sub

    Private Sub ComboBox_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim combo As ComboBox = CType(sender, ComboBox)
        Console.WriteLine("Row: {0}, Value: {1}, id: {2}", DataGridView2Rachunek.CurrentCell.RowIndex, combo.SelectedItem)

End Sub

这是点击第一个下拉菜单:

Private Sub DataGridViewRachunek_rowselected(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView2Rachunek.CellClick


    If e.RowIndex < 0 Then
        Exit Sub



    Else
            DataGridView2Rachunek.Rows(e.RowIndex).Selected = True


        If e.ColumnIndex = DataGridView2Rachunek.Columns("Stan").Index Then
            DataGridView2Rachunek.BeginEdit(True)

            DirectCast(DataGridView2Rachunek.EditingControl, ComboBox).DroppedDown = True
        End If


    End If

End Sub

一切都很好但有小虫。

示例:我有多行。如何预防bug?:

  • 在(示例)第2行和comboboxcolumn中选择一个选项,
  • 点击(例如)第1行和组合框然后发生这样: comboBox获取第2行的值大约0.2秒,然后返回到点击之前的值。

如果我删除事件以检测选择更改错误,则不会发生。

总的来说,它没有造成任何错误,只是视觉效果......你们有个想法我能用这个做些什么吗?

0 个答案:

没有答案