TreeView.SelectedNode.FullPath problem
-
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
-
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
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.
-
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.
Thanx man!.....great help....