本帖最后由 foxtable 于 2016-5-20 11:20 编辑
我之前是用下面的方法绕开这个问题,也许有参考价值:
Dim dt As Data.DataTable
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dt = New Data.DataTable
For i As Integer = 1 To 10
dt.Columns.Add("Col" & i, GetType(String))
Next
For i As Integer = 1 To 5
dt.Rows.Add(dt.NewRow)
Next
Me.C1FlexGrid1.DataSource = dt.DefaultView
Me.C1ComboBox1.DataSource = dt.DefaultView
Me.C1ComboBox1.DataField = "Col1"
Dim values() As String = {"a", "b", "c", "d", "e", "f"}
Me.C1ComboBox1.Items.AddRange(values)
Me.C1ComboBox1.ItemsImageList = Me.ImageList1
End Sub
Private Sub C1ComboBox1_SelectedItemChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles C1ComboBox1.SelectedItemChanged
Me.C1ComboBox1.Value = Me.C1ComboBox1.SelectedItem
If Me.C1ComboBox1.DataBindings.Count > 0 AndAlso Me.C1ComboBox1.DataBindings(0).BindingManagerBase.Count > 0 Then
Dim cur As Object = Me.C1ComboBox1.DataBindings(0).BindingManagerBase.Current
If TypeOf cur Is Data.DataRowView Then
Dim dr As Data.DataRow = CType(cur, Data.DataRowView).Row
Dim cn As String = Me.C1ComboBox1.DataBindings(0).BindingMemberInfo.BindingField
If dr(cn).ToString <> Me.C1ComboBox1.SelectedItem.ToString Then
Me.C1ComboBox1.Value = Me.C1ComboBox1.SelectedItem
Me.C1ComboBox1.DataBindings(0).WriteValue()
CType(cur, Data.DataRowView).Row.EndEdit()
End If
End If
End If
End Sub |