我已将网格的 DataSource 绑定到我从另一个线程更新的 BindingSource 对象。我写了以下代码:
protected override void OnPaint(PaintEventArgs pe)
{
if (this.InvokeRequired)
{
this.Invoke(new OnPaintMethodInvoker(this.OnPaint), pe);
}
else
{
try
{
base.OnPaint(pe);
}
catch
{
}
}
}
我发生了两件事:1. Invoke 从未被调用(我猜 Ultragrid 知道如何处理它) 2. 当我在更新数据时玩屏幕(鼠标悬停/调整大小)时 - 我收到以下信息例外:
指数数组的边界之外。
at Infragistics.Shared.SparseArray.GetItemAtScrollIndex(Int32 scrollIndex, ICreateItemCallback createItemCallback)
at Infragistics.Win.UltraWinGrid.ScrollCountManagerSparseArray.GetItemAtScrollIndex(Int32 scrollIndex, Boolean allocate)
at Infragistics.Win.UltraWinGrid.RowsCollection.GetRowAtScrollIndex(Int32 scrollIndex, Boolean allocate)
at Infragistics.Win.UltraWinGrid.RowsCollection.get_IsLastScrollableRowNotAllocatedYet()
at Infragistics.Win.UltraWinGrid.RowScrollRegion.IsLastScrollableRowVisible(ScrollbarVisibility colScrollbarVisibility)
at Infragistics.Win.UltraWinGrid.RowScrollRegion.GetMaxScrollPosition(Boolean scrollToFill)
at Infragistics.Win.UltraWinGrid.RowScrollRegion.EnsureScrollRegionFilled(Boolean calledFromRegenerateVisibleRows)
at Infragistics.Win.UltraWinGrid.RowScrollRegion.RegenerateVisibleRows(Boolean resetScrollInfo)
at Infragistics.Win.UltraWinGrid.RowScrollRegion.RegenerateVisibleRows()
at Infragistics.Win.UltraWinGrid.RowScrollRegion.WillScrollbarBeShown(ScrollbarVisibility assumeColScrollbarsVisible)
at Infragistics.Win.UltraWinGrid.ScrollRegionBase.WillScrollbarBeShown()
at Infragistics.Win.UltraWinGrid.RowScrollRegion.PositionScrollbar(Boolean resetScrollInfo)
at Infragistics.Win.UltraWinGrid.ScrollRegionBase.SetOriginAndExtent(Int32 origin, Int32 extent)
at Infragistics.Win.UltraWinGrid.RowScrollRegion.SetOriginAndExtent(Int32 origin, Int32 extent)
at Infragistics.Win.UltraWinGrid.DataAreaUIElement.ResizeRowScrollRegions()
at Infragistics.Win.UltraWinGrid.DataAreaUIElement.PositionChildElements()
at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive)
at Infragistics.Win.UltraWinGrid.DataAreaUIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive)
at Infragistics.Win.UltraWinGrid.DataAreaUIElement.set_Rect(Rectangle value)
at Infragistics.Win.UltraWinGrid.UltraGridUIElement.PositionChildElements()
at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive)
at Infragistics.Win.UltraWinGrid.UltraGridUIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive)
at Infragistics.Win.UIElement.DrawHelper(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Boolean clipText, Boolean forceDrawAsFocused, Boolean preventAlphaBlendGraphics)
at Infragistics.Win.UIElement.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Boolean forceDrawAsFocused, Boolean preventAlphaBlendGraphics)
at Infragistics.Win.ControlUIElementBase.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Size elementSize, Boolean preventAlphaBlendGraphics)
at Infragistics.Win.ControlUIElementBase.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Size elementSize)
at Infragistics.Win.ControlUIElementBase.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode)
at Infragistics.Win.UltraWinGrid.UltraGridUIElement.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode)
at Infragistics.Win.UltraControlBase.OnPaint(PaintEventArgs pe)
at Infragistics.Win.UltraWinGrid.UltraGrid.OnPaint(PaintEventArgs pe)
at MyProject.Common.UI.Controls.GridControl.OnPaint(PaintEventArgs pe)
任何人都知道可能是什么问题?我试图将 lock(this) 放在 base.OnPaint(pe) 周围,但没有帮助。