DataGridViewComboBoxColumn multiple click SelectedIndexChanged event

1.DataGridView中的comboBox需要点击2次或多次才能弹出下拉item

first:

Me.DataGridView1.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter
second:

 

 

If e.ColumnIndex >= 0 AndAlso e.RowIndex >= 0 AndAlso DataGridView1(e.ColumnIndex, e.RowIndex) IsNot Nothing _
                    AndAlso Not DataGridView1(e.ColumnIndex, e.RowIndex).ReadOnly Then
            Dim comboBoxColumn As DataGridViewComboBoxColumn = _
                            TryCast(DataGridView1.Columns(e.ColumnIndex), DataGridViewComboBoxColumn)
            If comboBoxColumn IsNot Nothing Then               

      DataGridView1.BeginEdit(False)
                Dim comboBoxEditingControl As DataGridViewComboBoxEditingControl = _
                            TryCast(DataGridView1.EditingControl, DataGridViewComboBoxEditingControl)
                If comboBoxEditingControl IsNot Nothing Then
                    comboBoxEditingControl.DroppedDown = True
                End If

            End If
        End If

 

 

2.向DataGridView中的comboBox添加SelectedIndexChanged后多次触发

 

Private Sub dgvBudgetDetail_EditingControlShowing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles dgvBudgetDetail.EditingControlShowing
        If dgvBudgetDetail.CurrentCell.ColumnIndex = 11 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.TextChanged,  New EventHandler(AddressOf ComboBox_SelectedIndexChanged)

                ' Add the event handler.
                AddHandler combo.TextChanged,   New EventHandler(AddressOf ComboBox_SelectedIndexChanged)

            End If
        End If
    End Sub

 

 

Private Sub ComboBox_SelectedIndexChanged(  ByVal sender As Object, ByVal e As EventArgs)
        Dim jj As Integer = dgvBudgetDetail.CurrentRow.Index
        Dim comboBox1 As ComboBox = CType(sender, ComboBox)

        If CType(sender, ComboBox).SelectedItem IsNot Nothing Then
         
 
        Else
            RemoveHandler comboBox1.TextChanged, _
                      New EventHandler(AddressOf ComboBox_SelectedIndexChanged)
        End If

    End Sub
 

 

 

 

 

 

 

posted @ 2011-12-31 16:11  kting  阅读(596)  评论(0编辑  收藏  举报