Anyone have any idea what causes this? It's an uncaught exception somewhere in my code when I try to change a property on the toolbar. Just not sure what's causing it...
See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.************** Exception Text **************System.NullReferenceException: Object reference not set to an instance of an object. at Infragistics.Win.UltraWinToolbars.UltraToolbarBase.ToolbarToolRow.InternalAddTool(ToolBase tool, Size toolSize, Boolean needsHorizontalSeparator) at Infragistics.Win.UltraWinToolbars.UltraToolbarBase.ToolGroup.CalculateMetrics(Int32 maxWidth) at Infragistics.Win.UltraWinToolbars.UltraToolbarBase.ToolbarMetrics.CalculateFloatingMetricsHelper(ToolGroup[ toolGroups, Int32 maxWidth) at Infragistics.Win.UltraWinToolbars.UltraToolbarBase.ToolbarMetrics.CalculateFloatingMetrics(Size cachedSize, Size delta) at Infragistics.Win.UltraWinToolbars.UltraToolbarBase.GetMetrics(Size cachedSize, Size delta) at Infragistics.Win.UltraWinToolbars.UltraToolbarBase.ToolAreaInformation.FromToolbar(UltraToolbarBase toolbar, Rectangle overallArea) at Infragistics.Win.UltraWinToolbars.ToolbarUIElement.PositionChildElements() at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UIElement.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.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) at Infragistics.Win.UltraControlBase.OnPaint(PaintEventArgs pe) at Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea.OnPaint(PaintEventArgs pe) at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs) at System.Windows.Forms.Control.WmPaint(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
This looks like it might be related to a threading issue, since the call stack begins with the NativeWindow.Callback. You should make sure that any actions that you take that might affect the UI thread are marshalled back to the main thread before being executed.
-Matt
You are very correct -- I believed I am marshalling back correctly, but I will triple check my code.
Travis
I hope someone sees this, but I cannot find an invoke required method for the toolbar -- can I just use the form invoke required to get the same affect?
Another question -- what would it hurt to ALWAYS invoke?
You should probably use the DockWithinContainer of the toolbars manager, which would generally be the form that it is contained on, to check the InvokeRequired (and also perform the invocation). While I'm not entirely sure what the effect is of calling Invoke always, it's still probably best to only do it when necessary.
I misunderstood you -- THANKS FOR THE SUPER QUICK RESPONSE!!
I just looked -- that means the UltraToolBarsManager or even the UltraToolBar objects do not have these methods available, I'm assuming there's some kind of invocation interface these controls did not implement...?
The DockWithinContainer of the manager should be used:
if(this.ultraToolbarsManager1.DockWithinContainer.InvokeRequired)
//Do Stuff
Thanks Matt, that's what I'm saying though -- I cannot find InvokeRequired on the toolbar manager -- am I missing something.
Thanks for the tip.