我在DGV上遇到绑定源问题。消息是" DataMember Property'节点'无法在dataSource"上找到将表设置为数据源后,列数为14。 nodeDataGridView.DataSource = bsNodes行上发生错误。如果我在错误之前中断然后将鼠标悬停在ds上,它确实显示表节点在数据源中。我使用了与此类似的代码来设置其他DGV,但我没有看到这个代码有任何区别。
如果我删除这些陈述,我就不会收到错误,但当然不会过滤掉):
nodesDataGridView.DataSource = bsNodes
bsNodes.Filter = "company_number = " & Globals.customer_id
我应该提一下,我在网格完成并正常工作后添加了company_number。它是针对单个公司代码设置的,但现在我不得不添加要求以支持数据库中的多个公司。
有什么想法吗?
谢谢,
维克
' Setup objects for loading the summary grid
Dim sqlNodes As String = "Select *From nodes order by display_sequence"
Dim comm As MySqlCommand = New MySqlCommand(sqlNodes, m_cn1)
Dim daNodes As MySqlDataAdapter = New MySqlDataAdapter(comm)
Dim dsNodes As DataSet = New DataSet()
dim bsNodes As New BindingSource
Try
AddHandler ButtonSaveChanges.Click, AddressOf ButtonSaveChanges_Click
dsNodes.Clear()
daNodes.Fill(dsNodes, "nodes")
m_cn1.Close()
nodesDataGridView.DataSource = dsNodes
nodesDataGridView.DataMember = "nodes"
bsNodes.DataSource = dsNodes.Tables("nodes")
Debug.Print("nodes column count is " & nodesDataGridView.ColumnCount)
nodesDataGridView.DataSource = bsNodes
bsNodes.Filter = "company_number = " & Globals.customer_id
Catch ex As Exception
MessageBox.Show("Failed to load summary grid" & vbCrLf & vbCrLf & ex.ToString)
End Try
答案 0 :(得分:0)
尝试像这样过滤
bsNodes.Filter = "company_number = '" & Globals.customer_id.ToString() & "'"
编辑:
bsNodes.DataSource = dsNodes.Tables("nodes")
nodesDataGridView.DataSource = bsNodes '<- you set dsNodes(Dataset) this should be the BindingSource not Dataset
nodesDataGridView.DataMember = "nodes"
Debug.Print("nodes column count is " & nodesDataGridView.ColumnCount)
'nodesDataGridView.DataSource = bsNodes
bsNodes.Filter = "company_number = '" & Globals.customer_id.ToString() & "'"