Click here to Skip to main content
15,885,985 members
Home / Discussions / C#
   

C#

 
Questioncreating an object? Pin
jinz25-Jan-03 11:27
jinz25-Jan-03 11:27 
AnswerRe: creating an object? Pin
Jeff J25-Jan-03 11:40
Jeff J25-Jan-03 11:40 
QuestionHow to get the index of a DataRow in a DataTable? Pin
lnong25-Jan-03 11:15
lnong25-Jan-03 11:15 
GeneralTreeNode checking Pin
Member 18598625-Jan-03 9:42
Member 18598625-Jan-03 9:42 
GeneralRe: TreeNode checking Pin
leppie25-Jan-03 10:52
leppie25-Jan-03 10:52 
GeneralRe: TreeNode checking Pin
Member 18598625-Jan-03 11:11
Member 18598625-Jan-03 11:11 
GeneralRe: TreeNode checking Pin
leppie25-Jan-03 11:35
leppie25-Jan-03 11:35 
GeneralRe: TreeNode checking Pin
Jeff J25-Jan-03 11:32
Jeff J25-Jan-03 11:32 
Your code is written well, but Contains() does not do what one might expect it to.

I have had exactly the same problem, and lost a lot of hair researching this. The CLR TreeView has no way of finding a node by name, even though the Contains() method looks like it would provide that functionality. Contains() returns true only if the node passed to it, is the exact same node as one already in the TreeNodeCollection. I do not see a lot of use for such functionality, but that is the way it is.

What we are interested in is a way to see if there is already a node with a specific name (or full path). There are a number of ways of testing this, and most rely on enumerating some nodes, and seeing if one of the names matches the one being sought. Incidentally, a TreeNodeCollection can contain multiple nodes with exactly the same name, which might be one reason searching for a "unique name" was not implemented.

In your case, it looks as though each node's name contains full path info, so this might not be too difficult. In my case, I had nodes branched-out into dir trees, which required parsing each path into separate dir names, and walking the tree.

Anyway, I enumerated by grabbing the node returned by FirstNode, which gets a node's first child node. With the node returned (if not null), I kept calling NextNode to get the rest of the child nodes. I did this until null was returned (no more child nodes). If there is a match, continue deeper if necessary, using the same methods (I used recursive calls).

In my case I wrote a search function that took an array of node names, which were parsed from the path to look for. I hope some of this helps.

Cheers
GeneralRe: TreeNode checking Pin
Member 18598625-Jan-03 11:51
Member 18598625-Jan-03 11:51 
Generalreflection Pin
jtmtv1825-Jan-03 6:21
jtmtv1825-Jan-03 6:21 
GeneralRe: reflection Pin
leppie25-Jan-03 6:43
leppie25-Jan-03 6:43 
Generalleppie read this...(or anyone) Pin
25-Jan-03 10:23
suss25-Jan-03 10:23 
GeneralRe: leppie read this...(or anyone) Pin
leppie25-Jan-03 22:34
leppie25-Jan-03 22:34 
GeneralRe: leppie read this...(or anyone) Pin
James T. Johnson26-Jan-03 6:11
James T. Johnson26-Jan-03 6:11 
GeneralRe: leppie read this...(or anyone) Pin
Paul Riley26-Jan-03 5:29
Paul Riley26-Jan-03 5:29 
GeneralDataRow problem Pin
Mr BallyDaHob25-Jan-03 5:54
Mr BallyDaHob25-Jan-03 5:54 
GeneralRe: DataRow problem Pin
leppie25-Jan-03 6:38
leppie25-Jan-03 6:38 
QuestionIntegrating Flex with C#??? Pin
anjana25-Jan-03 5:34
anjana25-Jan-03 5:34 
AnswerRe: Integrating Flex with C#??? Pin
leppie25-Jan-03 6:34
leppie25-Jan-03 6:34 
QuestionWhat to write? Pin
Skylinemailer25-Jan-03 3:59
Skylinemailer25-Jan-03 3:59 
AnswerRe: What to write? Pin
leppie25-Jan-03 4:33
leppie25-Jan-03 4:33 
AnswerRe: What to write? Pin
Vagif Abilov25-Jan-03 6:16
professionalVagif Abilov25-Jan-03 6:16 
GeneralDateTimePicker Control Pin
Mr BallyDaHob25-Jan-03 3:33
Mr BallyDaHob25-Jan-03 3:33 
GeneralRe: DateTimePicker Control Pin
leppie25-Jan-03 4:43
leppie25-Jan-03 4:43 
GeneralRe: DateTimePicker Control Pin
Mr BallyDaHob25-Jan-03 5:39
Mr BallyDaHob25-Jan-03 5:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.