Click to See Complete Forum and Search --> : How to detece a duplicate node while adding a new node to a tree list view control
dwaipeyan
March 5th, 2009, 03:51 AM
Hello Gururs,
can any one of you send me the code for :
How to detect a duplicate node in existing while adding a new node to a tree list view control in c#. or
Validation mechanism for duplicate nodes in tree view while adding new node.
Thanks,
Ranga,
dannystommen
March 5th, 2009, 10:17 AM
What is your definition of 'duplicate node'.
You could use the treenode.Nodes.ContainsKey method
for example
//supose whe have a Person class with properties Username, Firstname and Lastname (all string)
List<Person> persons = new List<Person>();
persons.Add(new Person("username1", "firstname1", "lastname1"));
persons.Add(new Person("username2", "firstname2", "lastname2"));
persons.Add(new Person("username1", "firstname1", "lastname1"));
foreach(Person p in persons){
if (! treeview1.Nodes.ContainsKey(p.Username)){
treeview1.Nodes.Add(p.Username, string.Format("{0} {1}", p.Firstname, p.Lastname));
}
}
After the executing of this code you only will have 2 persons in the treeview
dwaipeyan
March 8th, 2009, 11:09 PM
Hi,
Thank you very much for your solution.
But the tree control what I am using does not have this property method.
I am using DevX Tree view control.
Thanks
Arjay
March 8th, 2009, 11:30 PM
I'd use a container that doesn't allow duplicates and then bind the container to the control.
BigEd781
March 9th, 2009, 12:00 PM
If you are using the TreeView in unbound mode, you could create your own TreeNode class and define your own version of equality. If you are using data binding, take Arjay's advice.
dwaipeyan
March 10th, 2009, 11:54 PM
Hi all,
Thank you for your informations
I will try and update you
Thanks,
Ranga
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.