Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. TreeView.SelectedNode.FullPath problem

TreeView.SelectedNode.FullPath problem

Scheduled Pinned Locked Moved C#
questiondata-structurestestingbeta-testinghelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gerbenschmidt
    wrote on last edited by
    #1

    Hi, I have a form which must act like a custom directory browser. Now my code has one NodeMouseClick event which is handling 2 actions when selecting a TreeView Node: 1)Build the Items for the ListView (this works) 2)Show the Full path of the Selected Node in a StatusBar In my Code 2) (bold lines) returns the path of the previous clicked Node!!!....Has anyone an idea what is wrong?? // This is the Projects Path which is set in the Menu_Settings.cs file (an application setting) string sProjectsPath = global::Offshore_Supports_Menu.Properties.Settings.Default.Projects_Dir; // This "10.0159 Ormen Lange"; is based on the Project "Number & Name" filled in the "New Project" forms. // The "New Project" forms should store the user input data in somekind of project file. like an *.INI file // This *.INI file is loaded into the ProjectWindow.cs to view a custom explorer of the existing // or new generated typical project directory tree. // For testing purposes I typed a directory name "10.0159 Ormen Lange"; // but it should be inserted from the *.INI file string sProject = "10.3459 Ormen Lange II"; private void PopulateTreeView() { //The Project Directory Root Folder to begin the TreeView TreeNode rootNode; DirectoryInfo ProjectPath = new DirectoryInfo(sProjectsPath + "\\" + sProject); if (ProjectPath.Exists) { rootNode = new TreeNode(ProjectPath.Name); rootNode.Tag = ProjectPath; rootNode.ImageIndex = 2; rootNode.SelectedImageIndex = 2; GetDirectories(ProjectPath.GetDirectories(), rootNode); ProjectTreeView.Nodes.Add(rootNode); rootNode.Expand(); StatusLabel1.Text = ProjectPath.ToString(); } } void ProjectTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { TreeNode newSelected = e.Node; ProjectListView.Items.Clear(); DirectoryInfo nodeDirInfo = (DirectoryInfo)newSelected.Tag; ListViewItem.ListViewSubItem[] subItems; ListViewItem item = null; **if (ProjectTreeView.SelectedNode.IsSelected == true) { StatusLabel1.Text = sProjectsPath + "\\" + ProjectTreeView.SelectedNode.FullPath; }** //ListView item

    A 1 Reply Last reply
    0
    • G gerbenschmidt

      Hi, I have a form which must act like a custom directory browser. Now my code has one NodeMouseClick event which is handling 2 actions when selecting a TreeView Node: 1)Build the Items for the ListView (this works) 2)Show the Full path of the Selected Node in a StatusBar In my Code 2) (bold lines) returns the path of the previous clicked Node!!!....Has anyone an idea what is wrong?? // This is the Projects Path which is set in the Menu_Settings.cs file (an application setting) string sProjectsPath = global::Offshore_Supports_Menu.Properties.Settings.Default.Projects_Dir; // This "10.0159 Ormen Lange"; is based on the Project "Number & Name" filled in the "New Project" forms. // The "New Project" forms should store the user input data in somekind of project file. like an *.INI file // This *.INI file is loaded into the ProjectWindow.cs to view a custom explorer of the existing // or new generated typical project directory tree. // For testing purposes I typed a directory name "10.0159 Ormen Lange"; // but it should be inserted from the *.INI file string sProject = "10.3459 Ormen Lange II"; private void PopulateTreeView() { //The Project Directory Root Folder to begin the TreeView TreeNode rootNode; DirectoryInfo ProjectPath = new DirectoryInfo(sProjectsPath + "\\" + sProject); if (ProjectPath.Exists) { rootNode = new TreeNode(ProjectPath.Name); rootNode.Tag = ProjectPath; rootNode.ImageIndex = 2; rootNode.SelectedImageIndex = 2; GetDirectories(ProjectPath.GetDirectories(), rootNode); ProjectTreeView.Nodes.Add(rootNode); rootNode.Expand(); StatusLabel1.Text = ProjectPath.ToString(); } } void ProjectTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { TreeNode newSelected = e.Node; ProjectListView.Items.Clear(); DirectoryInfo nodeDirInfo = (DirectoryInfo)newSelected.Tag; ListViewItem.ListViewSubItem[] subItems; ListViewItem item = null; **if (ProjectTreeView.SelectedNode.IsSelected == true) { StatusLabel1.Text = sProjectsPath + "\\" + ProjectTreeView.SelectedNode.FullPath; }** //ListView item

      A Offline
      A Offline
      Alan N
      wrote on last edited by
      #2

      Hi, I suggest that you read through the full list of events that are available for the treeview control. There are so many it can be difficult to choose the correct one for any given situation but once you realise that the mouse events aren't needed for simple navigation and selection then you'll be on your way. The click event is the one of the first to arrive and is at too low a level for your requirement. Instead respond to the AfterSelect event which arrives only after the node you want is fully selected. When your code responds to the NodeMouseClick event the node you have just clicked is not yet selected which is why SelectedNode gets what appears to be the previous node. The eventargs e.Node which you pick up as newSelected will refer to the clicked upon node but like I said respond to AfterSelect and your code will do what you want it to. One last thing, SelectedNode.IsSelected == true, can be removed from your code as by definition the SelectedNode is selected. OK I'm just being picky, you probably put that in to try and figure what had gone wrong! Hope that helps, Alan.

      G 1 Reply Last reply
      0
      • A Alan N

        Hi, I suggest that you read through the full list of events that are available for the treeview control. There are so many it can be difficult to choose the correct one for any given situation but once you realise that the mouse events aren't needed for simple navigation and selection then you'll be on your way. The click event is the one of the first to arrive and is at too low a level for your requirement. Instead respond to the AfterSelect event which arrives only after the node you want is fully selected. When your code responds to the NodeMouseClick event the node you have just clicked is not yet selected which is why SelectedNode gets what appears to be the previous node. The eventargs e.Node which you pick up as newSelected will refer to the clicked upon node but like I said respond to AfterSelect and your code will do what you want it to. One last thing, SelectedNode.IsSelected == true, can be removed from your code as by definition the SelectedNode is selected. OK I'm just being picky, you probably put that in to try and figure what had gone wrong! Hope that helps, Alan.

        G Offline
        G Offline
        gerbenschmidt
        wrote on last edited by
        #3

        Thanx man!.....great help....

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups