DotNet · 2022年3月5日

DataGridViewComboBoxExEditingControl使用示例

如果每次选择项都不一样,则响应下面事件来实现

    Private Sub xDataGridView_EditingControlShowing(sender As Object, e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgsHandles xDataGridView.EditingControlShowing


If (TypeOf e.Control Is DataGridViewComboBoxExEditingControlThen
            If (xDataGridView.CurrentCell.ColumnIndex = mRunAfterColumn.Index) Then
                If (Not xDataGridView.CurrentCell.ReadOnly) Then
                    Dim pControl As DataGridViewComboBoxExEditingControl = CType(e.Control, DataGridViewComboBoxExEditingControl)

                    pControl.DataSource = getRunAfterColumnChildrenSelect(xDataGridView.CurrentCell.RowIndex)          pControl.SelectedIndex = pControl.FindStringExact(CStr(xDataGridView.CurrentCell.Value))
                End If
            End If

        End If

如果选择项是固定不变的,可以在Column级别赋值 

Dim pSelectList As List(Of EnrafCommand) = mGaugeConfig.mInnerExtend.enrafCommandConfig.ToList()
mRunAfterColumn.DataSource = pSelectList

此控件不支持

 ‘pControl.DisplayMember = EnrafCommand.displayMember
 ‘pControl.ValueMember = EnrafCommand.valueMember
如需要在界面上显示正确的内容,需要对像重载ToString()

如果选择项会丢失,则要设置列的属性DropDownStyle为DropDown(推荐)或Simple

    一般的Combox,在选择项丢失时,会不断抛出错误,导致程序无法正常执行下去

最新电影,电视剧,尽在午夜剧场

电影电视剧午夜不寂寞