我的第一篇文章,因为我找不到答案。
我有一个数据绑定GridView与一堆ComboBoxes。它们正确显示基础表中的值,并在下拉列表中显示正确的值。 Combobox中有一个有一个int .value成员,一切都很适合它。另一个ComboBox有字符串.valuemember,当我在组合框中选择一个不同的值时,它不会更新到绑定表。
它们使用相同表格和相同网格中的相同代码进行绑定和更新。我特意绑定到ESRI ArcGIS文件。它似乎被正确绑定,我已成功地将它用于其他项目。它会再次显示和更新所有列中的更改,并接受对基于整数的行的更改;因此,我可能会愚蠢地将其排除在外。
不确定我需要做什么来使字符串.valuemember值更新。
我想错过一些简单的东西,但我不知道它是什么。这是一些示例代码。
Domain1 As BindingList(Of Domaintype)
Domain2 As BindingList(Of Domaintype)
GridView.DataSource = pBindingSource
'add the columns desired
GridView.Columns.Add(CreateComboBoxColumn("Column1Value", "Type1", Domain1 , "NonCodedIntValue"))
GridView.Columns.Add(CreateComboBoxColumn("Column2Value", "Type2", Domain2 , "NonCodedCharValue"))
Private Function CreateComboBoxColumn(ByVal ColumnName As String, ByVal AliasName As String, ByRef DomainName As BindingList(Of Domaintype), ByVal pValueMember As String) As DataGridViewComboBoxColumn
CreateComboBoxColumn = New DataGridViewComboBoxColumn
With CreateComboBoxColumn
.DataPropertyName = ColumnName
.HeaderText = AliasName
.ReadOnly = False
End With
With CreateComboBoxColumn
.DataSource = DomainName
.DisplayMember = "CodedValue"
.ValueMember = pValueMember
End With
Return CreateComboBoxColumn
End Function
Private Sub GridView_CurrentCellDirtyStateChanged(ByVal sender As Object, ByVal e As EventArgs) Handles GridView.CurrentCellDirtyStateChanged
If GridView.IsCurrentCellDirty Then
GridView.CommitEdit(DataGridViewDataErrorContexts.Commit)
End If
End Sub
Public Class Domaintype
Private CodedValue As String
Private NonCodedInt As Nullable(Of Short)
Private NonCodedChar As String
'adds a new coded value based on a sent non-coded and coded value
Public Sub New(ByVal SentCodedValue As String, ByVal SentNonCoded As Nullable(Of Short), Optional ByVal SentNonCodedChar As String = Nothing)
CodedValue = SentCodedValue
NonCodedInt = SentNonCoded
NonCodedChar = SentNonCodedChar
End Sub
'Gets or sets the coded value of a domain
Public ReadOnly Property CodedValue() As String
Get
Return CodedValue
End Get
End Property
'gets or sets the non-coded value of a domain
Public ReadOnly Property NonCodedIntValue() As Nullable(Of Short)
Get
Return NonCodedInt
End Get
End Property
'gets or sets the non-coded value of a domain
Public ReadOnly Property NonCodedCharValue() As String
Get
Return NonCodedChar
End Get
End Property
End Class