How to detece a duplicate node while adding a new node to a tree list view control
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,
Re: How to detece a duplicate node while adding a new node to a tree list view contro
What is your definition of 'duplicate node'.
You could use the treenode.Nodes.ContainsKey method
for example
Code:
//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
Re: How to detece a duplicate node while adding a new node to a tree list view contro
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
Re: How to detece a duplicate node while adding a new node to a tree list view contro
I'd use a container that doesn't allow duplicates and then bind the container to the control.
Re: How to detece a duplicate node while adding a new node to a tree list view contro
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.
Re: How to detece a duplicate node while adding a new node to a tree list view contro
Hi all,
Thank you for your informations
I will try and update you
Thanks,
Ranga