如何解决'找不到名为 Brand_ID 的列参数名称:columnName'
尝试从数据网格中获取值,同时首先检查该值是否确实存在给了我一个问题,即该列不存在,即使它存在。
这是绑定代码;
dtBrands = fnGetmmBranchBrand(0)
If dtBrands IsNot nothing Then 'if the datatable exists
dvBrands.Table = dtBrands 'bind the datatable
If dvBrands.Table.Columns.Contains("Branch_ID") Then
dvBrands.RowFilter = "Branch_ID=" & intBranch_ID 'filter out all the records that aren't supposed to be in
End If
blProcessEvents = True 'set the semaphore to true here so that when the dg is populated the rows get filtered out of the comboBox
dgBrands.DataSource = dvBrands 'Fill the datagrid with the dv
end if
填充 dv 会按预期触发行添加事件处理程序
Private Sub dgBrands_RowsAdded(sender As Object,e As DataGridViewRowsAddedEventArgs) Handles dgBrands.RowsAdded
If blProcessEvents = True Then
'when a row is added count through all the rows that are in the datagrid
'and then refresh the results in the cbo based on the ones it didn't find in the dg
Dim intIndex As Integer = 0 'this is a counter
Dim strMasterFilter As String = "" 'clear the search string first
For intIndex = 0 To dgBrands.Rows.Count - 1 'count through all the rows in the dg
If dgBrands.Rows(intIndex).Cells("Brand_ID").Value IsNot nothing Then 'check if Brand_ID value exists in the datagrid
Dim intBrand_ID As Integer = dgBrands.Rows(intIndex).Cells("Brand_ID").Value 'grab the Brand_ID value and store it in a variable
end if
Next
但随后“如果 dgBrands.Rows(intIndex).Cells("Brand_ID").Value IsNot nothing Then”错误地说:'找不到名为 Brand_ID 的列。 参数名称:columnName' 这对我来说毫无意义,因为 Column 拼写正确, its part of the dv that is its datasource
最奇怪的是 MessageBox.Show(dgBrands.Columns.Count) = 1!,由于某种原因只显示了“ID”列.....
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。