1 Replies - 879 Views - Last Post: 08 September 2009 - 04:24 AM Rate Topic: -----

#1 Jarrhed  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 84
  • Joined: 01-January 09

Getting the number of the Selected item in the TreeView

Posted 07 September 2009 - 08:34 PM

I'm writing a program that involves listing a bunch of stuff in the treeview and I need to know what the number of the selected item is, like the first one is #1, 2nd one is #2 etc, how can I accomplish this? Here's some of the code from earlier in the file

foreach (XmlNode node in choices)
			{
				if (node.Attributes.Count == 6)
				{
					// Sets ChoiceTitltes to be the Title of the next item in line
					ChoiceTitles = node.Attributes["title"].InnerText;
					// Adds ChoiceTitle (The Title of each item) to ChoiceTitle in order that its in the Distribution File
					RemPKG_treeview.Nodes.Add(ChoiceTitles);
					// Increases the choiceamount for later use with finding which choice is selected and that ID, then later it will delete it from the Xmlfile and the package itself
					ChoiceAmount++;
					
				   // Selects the pkg-ref subnode of Choice
					XmlNode pkgrefchoice = doc.SelectSingleNode("installer-gui-script/choice/pkg-ref");
					// This statement is for declaring the array pkgidnumber, for 
					foreach (XmlNode Childnode in pkgrefchoice)
						{
							pkgidnumber[ChoiceAmount] = pkgrefchoice.Attributes["id"].InnerText;;

						}
					

				}
			   
				   
			}
					

		 }

private void DelPkg_button_Click(object sender, EventArgs e)
		{
			
		}




This code for the treeview would execute at the DelPKg_button_Click

Thanks

This post has been edited by Jarrhed: 07 September 2009 - 08:36 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Getting the number of the Selected item in the TreeView

#2 debjit625  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 51
  • View blog
  • Posts: 446
  • Joined: 06-September 08

Re: Getting the number of the Selected item in the TreeView

Posted 08 September 2009 - 04:24 AM

May be you are asking this...
TreeView have nodes so you can check which node is selected like this
Lets you have a TreeView named "treeView1" and add this in its After select event or where you want.
 private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
		{
			TreeNode t = treeView1.SelectedNode;//Get the selected node
			MessageBox.Show(t.Name);//Show the name of the selected node 
		}


Good Luck
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1