Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
520
Key already exists error in UltraWinTree
posted

 

I need to represent the following hierarchy in a tree control:

 

10001

    |

    +--10001-01

    |      |

    |      +-- A

    |      |

    |      +-- B

    |

    +--10001-02

           |

           +-- A

           |

           +-- C

Here is my code, which gives me the dup key error on adding the 10001-02->A node:

 

            UltraTreeNode node = null, childNode = null;

            foreach (DataRow row in dt.Rows)

            {

                curAccount = (string)row["AccountCode"];

                curSubAccount = (string)row["SubAccountCode"];

                curFund = (string)row["FundShortName"];

 

                int accountId = (int)row["AccountId"];

                int subAccountId = (int)row["SubAccountId"];

                int fundId = (int)row["FundId"];

 

                if (curAccount != prevAccount)

                {

                    Trace.WriteLine("Added node " + curAccount);

                    node = tvInvestor.Nodes.Add(curAccount);

                }

                else

                {

                    node = tvInvestor.Nodes[curAccount];

                }

 

                if (curSubAccount != prevSubAccount)

                {

                    Trace.WriteLine("Added child node " + curSubAccount);

                    childNode = node.Nodes.Add(curSubAccount);

                    Trace.WriteLine("Child node children count = " + childNode.Nodes.Count);

                }

                else

                    childNode = node.Nodes[curSubAccount];

 

                Trace.WriteLine("Adding grandchild node " + curFund);

                childNode.Nodes.Add(curFund); -- > Error on this line

 

                prevAccount = (string)row["AccountCode"];

                prevSubAccount = (string)row["SubAccountCode"];

            }

 

What am I doing wrong?