2013-03-21 21 views
0

我試圖在datagridview中進行搜索,循環遍歷每個單元格並比較兩個字符串 - SearchString和CellString。VB.NET BindingSource不能是它自己的數據源... datagridview中的錯誤

我把工作分成四個線程(通過給每個線程一個不同的四行處理器)並行工作。線程不能同時讀取同一個單元,因爲它們循環通過不同的行,所以我不認爲這個錯誤在那裏。

每個線程執行以下操作:

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。此外,我不做任何更新,我只讀取每個單元格作爲字符串。

我找不到任何類似的問題,所以任何幫助表示讚賞!

+0

你不能在數據源本身而不是DGV上執行搜索嗎? – rheitzman 2013-08-09 17:22:52

回答

0

沒有看到你的整個代碼,它很難正確回答問題,但是一切都指向你試圖從你正在創建的線程訪問你的UI的一些元素(這是Datagridview的一部分)。

據微軟稱,這是不合法的:

通過設計,Windows窗體或控件的方法不能比創建窗體或控制

檢查this article的另一個線程調用更多信息。它幫助我解決了類似的問題。

相關問題