我的第一篇文章,因为我找不到这个问题的答案。
我有一个带有一堆组合框的数据绑定 GridView。它们正确显示基础表中的值,并且正确的值出现在下拉列表中。1 个 Comboboxes 有一个 int .valuemember,一切都很好。另一个 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