我已经搜索过这个,但没有一个答案似乎有帮助。我在尝试填充数据网格时遇到此错误
ItemsControl与其商品来源不一致。
抛出此异常是因为名为'(未命名)'的控件'ExtendedGrid.ExtendedGridControl.ExtendedDataGrid Items.Count:9'的生成器收到了与Items集合的当前状态不一致的CollectionChanged事件序列。检测到以下差异: 累计计数8与实际计数9不同。[累计计数为(最后一次重置计数+ #Adds - 自上次重置后自#Removes)。]
我可以使用thread.sleep让它在80%的时间内工作,但是当它出现在其他机器上时,即使是80%也不会有效。
我正在使用后台工作程序填充此列表,然后使用ExtendedGrid.dll将该列表绑定到数据网格。后台工作程序的代码是:
Private Sub SalesHistoryBackgroundWorker_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles Me.DoWork
Dim ss As New OperaDAL.hsanalSelects(_DBPath)
Dim l As List(Of hsanal)
If _cstwh Is Nothing Then
l = ss.GethsanalByAccount(_SN_Account, True)
Else
l = ss.GethsanalByProduct(_cstwh.cs_ref, True)
End If
l.Reverse()
For Each i In l
If Not Me.CancellationPending Then
_History.Add(i)
Else
Exit For
End If
Next
If Not Me.CancellationPending Then
While l.Count > 0
Dim theS = l(0)
If theS.sa_product.Trim <> "" Then
Dim toOut = (From a In l.AsParallel Where theS.sa_product = a.sa_product Select a).ToList
If toOut.Count > 0 Then
Dim SumQty = (From a In toOut Select a.sa_qty).Sum
Dim SumValue = (From a In toOut Select a.sa_trvalue).Sum
If Not Me.CancellationPending Then
_HistoryView.Add(New GroupHSAnal(toOut.First.sa_product, toOut.First.cn_desc, SumQty, SumValue))
Do While toOut.Count > 0
Dim item = toOut(0)
l.Remove(item)
toOut.RemoveAt(0)
Loop
Else
l.Clear()
End If
End If
Else
Dim toOut = (From a In l.AsParallel Where a.sa_product.Trim = "" And a.sa_desc.Trim.ToUpper = theS.sa_desc.Trim.ToUpper Select a).ToList
If toOut.Count > 0 Then
Dim SumQty = (From a In toOut Select a.sa_qty).Sum
Dim SumValue = (From a In toOut Select a.sa_trvalue).Sum
If Not Me.CancellationPending Then
Thread.Sleep(6)
_HistoryView.Add(New GroupHSAnal("", toOut.First.sa_desc, SumQty, SumValue))
Do While toOut.Count > 0
Dim item = toOut(0)
l.Remove(item)
toOut.RemoveAt(0)
Loop
Else
l.Clear()
End If
End If
End If
End While
End If
_CanceledOk = True
End Sub
如果有人知道解决方案会有很大的帮助。
谢谢, 萨姆
答案 0 :(得分:0)
问题解决了必须设置.net 4.0到4.5的目标框架。然后我能够使用4.0中没有的EnableCollectionSynchronization方法,现在已经修复了这个错误。