My app adds nodes in 2 ways.
In one case it specifies both a key and text.In the other it specifies text only (null key)
Occasionally [for no obvious reason] the tree is replaced by a large red X and a message box says Item has already been added. Key in dictionary: "Teradata SQL"
This occurs in response to an event - not due to a call from within my code. (It seems to be a Paint event - see trace below)
The problem is that I have searched my entire source base (including resource files) and the only time the string "Teradata SQL" is used it is used for the TEXT property - not the KEY.
Could the Tree somehow get confused if I am adding the nodes within a BeginUpdate/EndUpdate block and specifying a null key?
How can a paint event (which I have no handler for) cause it to attempt to add a node?
Is there any way to trap this error?Maybe add a Paint handler that simply calls your paint handler from inside a catch block ... but I think it is too late by then.
Traceback:
System.ArgumentException: Item has already been added. Key in dictionary: 'Teradata SQL' Key being added: 'Teradata SQL' at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add) at System.Collections.Hashtable.Add(Object key, Object value) at Infragistics.Win.UltraWinTree.NodeClientAreaUIElement.CacheNodeElements(Hashtable table, UIElementsCollection oldElements, Int32 startIndex) at Infragistics.Win.UltraWinTree.NodeClientAreaUIElement.PositionChildElements() at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UIElement.VerifyChildElements(Boolean recursive) at Infragistics.Win.UIElement.VerifyChildElements() at Infragistics.Win.UltraWinTree.UltraTreeUIElement.PositionChildElements() 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.UltraWinTree.UltraTree.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)
ThanksMike
If I can not fix the problem is there a way I can work around it?
I can create my own class that derives from the UltraTree and override only the OnPaint() method.This event would simply call its base method from within a Try/Catch block.
I could call Invalidate() or Refresh() from within the Catch block to repaint the control, but if the problem is in your internal Hash Table it would probably go into a loop. Is there a way for me to blow away your hash table so that it would get rebuilt from the actual data in the Tree?
Is there another alternative - short of clearing all the tree nodes and reloading from scratch?
(I know from the tooltips that the underlying data still exists in the tree, and looks correct.)
I am not even able to replicate the problem on my systems (XP or Win7) but my tester in India can frequently replicate the problem. (Originally only on Win7, but now only on XP)
Can you have someone check to see if something was changed in the UltraTree (or the HashTable it uses during painting) since version 10.3. We never saw this problem until we upgraded to 11.2.
Hello,
If you are able to isolate this issue in a small sample and give me the exactly steps (and other details like Operating System and etc.), which I should follow in order to reproduce this issue on my machine, I will be glad to investigate this further for you. Without sample, we only could make guesses, what could be the reason for this issue.
I ma waiting for your feedback.
No luck so far.
I replaced all the code where I used Nodes.Add() followed by node.Text=xxx with Nodes.Add("", xxx).
Logically it should make no difference but I thought maybe the use of the empty constrctor (which I had never used in the previous version) might somehow be causing the problem.
With that new build my tester is no longer able to replicate the problem on Windows7 but he can now replicate it on XP. Exactly the opposite of the previous build.
The real problem is that the 'Key' it is reporting as a duplicate is NEVER used as a key. It is however used as the Text of a node - and it may be used as the Text of more than one node at times.
I have already sent a demo showing a regression in the 11.2 version of the Tree control related to disposed Tooltips and it is looking very much like this is another regression in the creation/use of the HashTable used in your Paint event. Could you check if anything has changed in reguard to this hash table between 10.3 and 11.2.
As far as removing threading from the application; that's just not possible. This has been a multi threaded application for a long time. (and we did not have these problems in earlier versions)Although a worker thread is used to fetch data that will later be loaded into a Tree control [but not the Tree that is crashing] even that data is loaded in the main thread. The tree controls are not referenced from within any worker thread - only from the main thread - so I don't see how threading can have any impact here.
b
Hi,
I just wanted to know if you were able to solve your issue based on Mike's suggestions or you still need help? Just let me know.
Thank you.