'找不到名为 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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...