【问题标题】:VB.NET BindingSource cannot be its own data source ... error in a datagridviewVB.NET BindingSource 不能是它自己的数据源... datagridview 中的错误
【发布时间】:2013-03-21 16:10:01
【问题描述】:

我正在尝试在 datagridview 中进行搜索,遍历每个单元格并比较 2 个字符串 - SearchString 和 CellString。

我将工作分成四个并行工作的线程(通过为每个线程分配不同的四分之一行来处理)。线程不能同时读取同一个单元格,因为它们循环遍历不同的行,所以我认为不存在错误。

每个线程执行以下操作:

   dim CellString as string
   For i As Integer = startrow To endrow

        For Each cell As DataGridViewCell In DataGridView.Rows(i).Cells

            CellString = cell.Value.ToString.ToLower ''Error appears here

            If cell.ColumnIndex <> 4 Then
                Select Case Compare(CellString, SearchString) ''complex function that compares 2 strings

                   ''....
                End Select
            End If
        Next
  Next

我得到的错误是:

BindingSource 不能是它自己的数据源。不要将 DataSource 和 DataMember 属性设置为引用回 BindingSource 的值。

我不明白为什么会发生这种情况,因为我没有搞乱 BindingSource 也没有搞乱 DataSource。此外,我不做任何更新,我只将每个单元格读取为字符串。

我找不到任何类似的问题,所以任何帮助表示赞赏!

【问题讨论】:

  • 你不能在数据源本身而不是 DGV 上执行搜索吗?

标签: vb.net datagridview bindingsource


【解决方案1】:

没有看到您的整个代码,很难准确地回答这个问题,但一切都表明您正试图从您正在创建的线程中访问您的 UI 的某些元素(Datagridview 是其中的一部分)。

根据微软的说法,这是不合法的:

按照设计,不能在创建窗体或控件的线程以外的线程上调用 Windows 窗体或控件方法

查看this article 了解更多信息。它帮助我解决了类似的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-30
    • 1970-01-01
    • 1970-01-01
    • 2017-09-17
    • 2021-09-15
    • 2012-02-09
    相关资源
    最近更新 更多