|
-
March 5th, 2009, 04:51 AM
#1
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,
Last edited by dwaipeyan; March 5th, 2009 at 04:55 AM.
-
March 5th, 2009, 11:17 AM
#2
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
-
March 8th, 2009, 11:09 PM
#3
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
-
March 8th, 2009, 11:30 PM
#4
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.
-
March 9th, 2009, 12:00 PM
#5
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.
-
March 10th, 2009, 11:54 PM
#6
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|