大家好,我有一个从绑定源很好地填充的组合框。所以问题是数据网格“名称”的列只显示来自填充下拉列表的值。那些与下拉列表不同的值显示为空。有人能告诉我为什么吗?下面是组合框的代码。我无法打印屏幕,但描述是这样的。LIst 有 3 个名称:John、Jake、Jay,但该列有超过 10 个名称,每个名称都在其各自的单元格中。加载时的问题没有显示其他名称。
Dim c4 As New DataGridViewComboBoxColumn()
c4.HeaderText = "Name"
c4.Name = "Name"
c4.DataPropertyName = "Name"
c4.DisplayMember = "NamesWithJ"
c4.ValueMember = "NamesWithJ"
c4.DisplayStyleForCurrentCellOnly = False
c4.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing
c4.FlatStyle = FlatStyle.Standard
c4.SortMode = DataGridViewColumnSortMode.Automatic
c4.DataSource = AddtBndSrc
c4.Width = 100
Me.DataGrid.Columns.Add(c4)
这是我创建绑定源并用值填充它的代码。完美显示的连接没有错误。只是组合框列在某些行中显示为空
Try
con = New SqlConnection(strConnection)
cib.Open()
adoAAda = New SqlDataAdapter(StrAddNameQuery, con)
adoAddtRs = New DataSet
adoAAda.Fill(adoAddtRs)
Dim tableAddt As DataTable = adoAddtRs.Tables(0)
Dim colum As DataColumn = tableAddt.Columns(0)
tableAddt.PrimaryKey = New DataColumn() {tableAddt.Columns(0)}
AddtBndSrc.DataSource = adoAddtRs.Tables(0)
con.close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Try
' connection procedure
con = New SqlConnection(strConnection)
con.Open()
adoPAda = New SqlDataAdapter(StrProductQuery, con)
adoProductsRS = New DataSet
adoPAda.Fill(adoProductsRS)
Dim tableProduct As DataTable = adoProductsRS.Tables(0)
Dim colum As DataColumn = tableProduct.Columns(0)
tableProduct.PrimaryKey = New DataColumn() {tableProduct.Columns(0)}
productBndSrc.DataSource = adoProductsRS.Tables(0)
MsgBox(tableProduct.Columns(0).ColumnName.ToString)
con.close
datagridview.Datasource = productBndSrc
Catch ex As Exception
MsgBox(ex.Message)
End Try