Click here to Skip to main content
15,900,254 members
Home / Discussions / C#
   

C#

 
AnswerRe: Newbie question about TreeNodeCollection vs TreeNode Pin
Wendelius16-Jan-09 7:54
mentorWendelius16-Jan-09 7:54 
Please use pre tags for code blocks. It makes the reading easier.

The first method return the node added so you can use it's properties on the calling side:
...
TreeNode addedNode = AddNode(MyTreeView.Nodes, "New node text");
addedNode.Tag = "XYZ";
addedNode.ImageIndex = 123;
...

Or if you want, add a variable inside the method and assign the properties you want in the method:
TreeNode AddNode(TreeNodeCollection Parent, string text)
{
   TreeNode temporaryNode;

   foreach (TreeNode node in Parent)
   {
      if (node.Text == text)
         return node;
   }
   temporaryNode = Parent.Add(text);
   temporaryNode.Tag = "XYZ";
   temporaryNode.ImageIndex = 123;
   ...
   return temporaryNode;
}

The same idea goes with the other method.

In all cases you may have to add parameters to the methods or extra logic how you decide what tag, imageindex etc is set.

This is quite basics, so I think you should get a good book concerning C# programming.

The need to optimize rises from a bad design.My articles[^]

GeneralRe: Newbie question about TreeNodeCollection vs TreeNode Pin
Rafone16-Jan-09 9:17
Rafone16-Jan-09 9:17 
GeneralRe: Newbie question about TreeNodeCollection vs TreeNode Pin
Wendelius16-Jan-09 9:26
mentorWendelius16-Jan-09 9:26 
GeneralRe: Newbie question about TreeNodeCollection vs TreeNode Pin
Rafone16-Jan-09 10:00
Rafone16-Jan-09 10:00 
GeneralRe: Newbie question about TreeNodeCollection vs TreeNode Pin
Wendelius16-Jan-09 10:05
mentorWendelius16-Jan-09 10:05 
GeneralRe: Newbie question about TreeNodeCollection vs TreeNode Pin
Rafone16-Jan-09 10:49
Rafone16-Jan-09 10:49 
QuestionWhat's your suggestion ? Pin
Mohammad Dayyan16-Jan-09 4:56
Mohammad Dayyan16-Jan-09 4:56 
AnswerRe: What's your suggest ? Pin
TylerBrinks16-Jan-09 4:59
TylerBrinks16-Jan-09 4:59 
AnswerRe: What's your suggest ? Pin
User 665816-Jan-09 5:40
User 665816-Jan-09 5:40 
AnswerRe: What's your suggest ? Pin
Wendelius16-Jan-09 6:44
mentorWendelius16-Jan-09 6:44 
GeneralRe: What's your suggest ? Pin
Mohammad Dayyan16-Jan-09 6:53
Mohammad Dayyan16-Jan-09 6:53 
GeneralRe: What's your suggest ? Pin
Wendelius16-Jan-09 7:00
mentorWendelius16-Jan-09 7:00 
QuestionComboBox in a Datagrid Pin
indian14316-Jan-09 3:38
indian14316-Jan-09 3:38 
AnswerRe: ComboBox in a Datagrid Pin
Henry Minute16-Jan-09 4:26
Henry Minute16-Jan-09 4:26 
AnswerRe: ComboBox in a Datagrid Pin
Jim (SS)16-Jan-09 5:34
Jim (SS)16-Jan-09 5:34 
QuestionFull trust network share problem during unit testing vs2008 on vista x64 (caspol solution does not work). Pin
Dennis Dam16-Jan-09 2:53
Dennis Dam16-Jan-09 2:53 
QuestionRetrieve Filenames Distinctively Pin
Vimalsoft(Pty) Ltd16-Jan-09 2:21
professionalVimalsoft(Pty) Ltd16-Jan-09 2:21 
AnswerRe: Retrieve Filenames Distinctively Pin
Pete O'Hanlon16-Jan-09 2:38
mvePete O'Hanlon16-Jan-09 2:38 
GeneralRe: Retrieve Filenames Distinctively Pin
Vimalsoft(Pty) Ltd16-Jan-09 3:11
professionalVimalsoft(Pty) Ltd16-Jan-09 3:11 
GeneralRe: Retrieve Filenames Distinctively Pin
Pete O'Hanlon16-Jan-09 3:59
mvePete O'Hanlon16-Jan-09 3:59 
GeneralRe: Retrieve Filenames Distinctively Pin
#realJSOP16-Jan-09 5:35
professional#realJSOP16-Jan-09 5:35 
AnswerRe: Retrieve Filenames Distinctively [modified] Pin
Luc Pattyn16-Jan-09 6:56
sitebuilderLuc Pattyn16-Jan-09 6:56 
AnswerRe: Retrieve Filenames Distinctively Pin
Ashfield16-Jan-09 2:42
Ashfield16-Jan-09 2:42 
AnswerRe: Retrieve Filenames Distinctively Pin
User 665816-Jan-09 2:51
User 665816-Jan-09 2:51 
AnswerRe: Retrieve Filenames Distinctively Pin
Vikram A Punathambekar16-Jan-09 3:15
Vikram A Punathambekar16-Jan-09 3:15 

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.