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
105
Set Allow Duplicate Keys
posted
Is it possible to set 'AllowDuplicateKeys' somehow? Is this possible anyway? I get errors when I want to add 2 nodes with the same keys? Erik
Parents
No Data
Reply
  • 944
    posted

     You can have as many nodes with 'null' keys as you like, but once you start setting keys, they must all be unique.

     I had the same issue in a project I am working on. With mine, the treeview was populated by a dataset. The root node (level 0)  and child (Level 1)would always be unique, however it was possible for a level 2 node to be trying to set the same key as a level 2 node under a different level 1 parent. I could not leave the keys as null as the key values formed the Primary Keys in the Database, so I always needed them.

    What I ended up doing was concantenating value I wanted to use for the level 2 key with the key of its parent (I used a pipe '|' as a delimiter). That way I could guarantee each node key was unique for my purposes. Then if you need to, you can always extract the required key value back again by extracting everything before or after your pipe, depending on what you need to extract. 

    I hope this helps give you an idea suitable for what you need.

    Cheers
    Jason Big Smile

Children