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
Hello ,
If you try to add a UltraTreeNode to UltraTree Nodes collection, and the key of this node already exist into the UltraTree Nodes collection, then you will get ArgumetException . If you use Add(string value) method then the new added node will have as a key the value which you were pas as parameter. I am not exactly sure why you get this red X and as you said this kind of issues happens with painting of the component, so I assume that you are adding your nodes in some background thread and that is why the exeption is trough in the background thread and the result is in the main UI thread. My suggestion is to add your nodes in BeginUpdate()/EndUpdate() bloc and to check if there already exist a node with the same key. To do this you could use code like:
if(ultraTree1.GetNodeByKey(key) == null)
ultraTree1.Nodes.Add(key);
Please let me know if you have any further questions.
That's the problem - I already do what you suggest.
I use Add(Key, Text) in most cases and the value it is complaining about is specified in the Text parameter - never the Key parameter.(Only one item is added at a time so I dont use BeginUpdate/EndUpdate here)
In another place I use Add() and then specify the Text - but not the Key - so the key defaults to something like 'Node34'.(This is the case that adds multiple nodes so I do use BeginUpdate/EndUpdate here)
In addition, when I use the Add(Key,Text) function it is already surrounded by a test to ensure that the key does not already exist. (as in your example)
That is why I'm asking if there is any way that it can get the 2 mixed up - or if there is some case in which it uses the Text as a Key if I do not specifically set a key.
One additional point - I only saw this problem one time on WindowsXP and that was back in the early development when I probably didn't check for the existance of the key first.My test engineer tells me it now happens frequently on Windows7 but he has never seen the problem on XP... so the same code seems to work differently on Win7. I know you have a different 'look' when I set it to Windows7 so do you do anything else differently?
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.
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.
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 have created a support ticket for you with id CAS-84102-752GMV, in order to investigate this issue further for you.
Thank you for using Infragistics Components.
Hi,
Has this issue been resolved? If so, is there an upgrade available?
I am struggling with the exact same problem.
The state of this issue is resolved it should be included in the upcoming Service release.