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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Selected TreeView Item [modified]

Selected TreeView Item [modified]

Scheduled Pinned Locked Moved C#
helpcsharpc++tutorialvisual-studio
5 Posts 4 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.
  • A Offline
    A Offline
    Alan Martinis
    wrote on last edited by
    #1

    Hi, please help me if you know how… Something is bothering me - something that I didn't know how to handle it using Visual C++, therefore I don't know how to do it now with C#. Description: I have form with SplitContainer control on it, where on the left side I have TreeView control, and on the right side, I would like (depending on selected item in TreeView ctrl) to have different set of other controls (buttons, editBox,…etc.) Correct me if I'm wrong – the only easiest way that came up my mind is PANNEL control. Number of panels should be the same as number of items in the TreeView control. After on in the application, depending of selected item, I can use method .Hide() or .Show() to manipulate those panels. Example For example I have 20 items in TreeView control, therefore I should have 20 different panels. Furthermore, when I have 20 panels on the same form, and each of them is covering right side of SplitContainer (complete area), the only panel I can see is the latest one (twentieth). With this „panel“ concept, issue I found here is in the case if I have to change something on the third panel (e.g. to add new checkBox on it) . How to reach third panel? Do I have to move 17 panels to one side in order to reach third one (to be visible to work on it)? I believe that there should be something more elegantly – but I don't know what? I use SharpDevelop, but if you know that solution for my problem have solution in Visual Studio, please suggest! Great example will be Computer Management Console. If you click on “Removable Storage” or “Disk Defragmenter” or any other item in TreeView control, depending on it on the right side you will have respectively related set of controls. Thanks, Alan -- modified at 2:01 Sunday 26th November, 2006

    B D 2 Replies Last reply
    0
    • A Alan Martinis

      Hi, please help me if you know how… Something is bothering me - something that I didn't know how to handle it using Visual C++, therefore I don't know how to do it now with C#. Description: I have form with SplitContainer control on it, where on the left side I have TreeView control, and on the right side, I would like (depending on selected item in TreeView ctrl) to have different set of other controls (buttons, editBox,…etc.) Correct me if I'm wrong – the only easiest way that came up my mind is PANNEL control. Number of panels should be the same as number of items in the TreeView control. After on in the application, depending of selected item, I can use method .Hide() or .Show() to manipulate those panels. Example For example I have 20 items in TreeView control, therefore I should have 20 different panels. Furthermore, when I have 20 panels on the same form, and each of them is covering right side of SplitContainer (complete area), the only panel I can see is the latest one (twentieth). With this „panel“ concept, issue I found here is in the case if I have to change something on the third panel (e.g. to add new checkBox on it) . How to reach third panel? Do I have to move 17 panels to one side in order to reach third one (to be visible to work on it)? I believe that there should be something more elegantly – but I don't know what? I use SharpDevelop, but if you know that solution for my problem have solution in Visual Studio, please suggest! Great example will be Computer Management Console. If you click on “Removable Storage” or “Disk Defragmenter” or any other item in TreeView control, depending on it on the right side you will have respectively related set of controls. Thanks, Alan -- modified at 2:01 Sunday 26th November, 2006

      B Offline
      B Offline
      Bassam Saoud
      wrote on last edited by
      #2

      You want to create controls based on the selected treeview item? If so why not create the controls dynamically? That is , based on the value of the selected item, you create the controls and add them to a placeholder.So instead of 20 panels all you need is a placeholder where you add your created controls to.Hope this helps....

      A 1 Reply Last reply
      0
      • B Bassam Saoud

        You want to create controls based on the selected treeview item? If so why not create the controls dynamically? That is , based on the value of the selected item, you create the controls and add them to a placeholder.So instead of 20 panels all you need is a placeholder where you add your created controls to.Hope this helps....

        A Offline
        A Offline
        Alan Martinis
        wrote on last edited by
        #3

        Thank you for idea (better to have something than nothing). I never did create any control dynamically - It is far easy to create control with some visual tool than to type size, distance between them,.. manually. From another forum, one developer advice me to use "UserControl". What do you think of that? Thank you!

        S 1 Reply Last reply
        0
        • A Alan Martinis

          Hi, please help me if you know how… Something is bothering me - something that I didn't know how to handle it using Visual C++, therefore I don't know how to do it now with C#. Description: I have form with SplitContainer control on it, where on the left side I have TreeView control, and on the right side, I would like (depending on selected item in TreeView ctrl) to have different set of other controls (buttons, editBox,…etc.) Correct me if I'm wrong – the only easiest way that came up my mind is PANNEL control. Number of panels should be the same as number of items in the TreeView control. After on in the application, depending of selected item, I can use method .Hide() or .Show() to manipulate those panels. Example For example I have 20 items in TreeView control, therefore I should have 20 different panels. Furthermore, when I have 20 panels on the same form, and each of them is covering right side of SplitContainer (complete area), the only panel I can see is the latest one (twentieth). With this „panel“ concept, issue I found here is in the case if I have to change something on the third panel (e.g. to add new checkBox on it) . How to reach third panel? Do I have to move 17 panels to one side in order to reach third one (to be visible to work on it)? I believe that there should be something more elegantly – but I don't know what? I use SharpDevelop, but if you know that solution for my problem have solution in Visual Studio, please suggest! Great example will be Computer Management Console. If you click on “Removable Storage” or “Disk Defragmenter” or any other item in TreeView control, depending on it on the right side you will have respectively related set of controls. Thanks, Alan -- modified at 2:01 Sunday 26th November, 2006

          D Offline
          D Offline
          darkelv
          wrote on last edited by
          #4

          You can use Panel, Form, Custom Controls as container for "the right side". If you can categorize the items on the tree view, you shouldn't have to have 1 panel/form/customcontrol for each treeview node. There is a .Tag property where you can assign an object to. You can set this property to the object that is tied to the treenode. I am using Form as a container as an exmaple here. Let's say there are 5 categories of stuff (Class1-Class5)you want to display. when you generate the treeview's node, assign the object to the node: TreeNode treeSalesOrder = new TreeNode("Class1 Object"); treeSalesOrder.Tag = class1_from_somewhere; etc etc So now you have a treeview with node that has tag tied to various objects. Have 5 forms that display these 5 classes (DisplayClass1-DisplayClass5) On the AfterSelect event private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { if (e.Node.Tag != null) { SetDisplayPanel(e.Node.Tag); } else { SetDisplayPanel(null); } } private void SetDisplayPanel(object obj) { this.panelDisplayOnRightSide.Controls.Clear(); if (obj != null) { Form form = null; if (obj is Class1) { form = new DisplayClass1((Class1)obj); } else if (obj is Class2) { form = new DisplayClass2((Class2)obj); } else if (obj is Class3) { form = new DisplayClass3((Class3)obj); } else if (obj is Class4) { form = new DisplayClass4((Class4)obj); } else if (obj is Class5) { form = new DisplayClass5((Class5)obj); } else { return; } form.ControlBox = false; form.FormBorderStyle = FormBorderStyle.None; form.Dock = DockStyle.Fill; form.MaximizeBox = false; form.MinimizeBox = false; form.TopLevel = false; //form.Object = obj; panelDisplayOnRightSide.Controls.Add(form); form.Show(); form.BringToFront(); } } Now I only ripped this code from a prototype program. You can add functions that reuse the 5 form

          1 Reply Last reply
          0
          • A Alan Martinis

            Thank you for idea (better to have something than nothing). I never did create any control dynamically - It is far easy to create control with some visual tool than to type size, distance between them,.. manually. From another forum, one developer advice me to use "UserControl". What do you think of that? Thank you!

            S Offline
            S Offline
            Scott Dorman
            wrote on last edited by
            #5

            User controls would essentially be the "best of both worlds". You would create 20 different user controls that represent the different screens you want displayed based on the selected tree node. The benefit here is that you can use the designers and don't have multiple panels stacked on top of each other. In the right-hand side of the splitter, you would place one panel that will be used to dynamically hold your user controls. In the AfterSelect event handler of the tree control you will need to do something like this (this is untested code, so it may not be exact):

            UserControl userControl;

            userControl.Dock = DockStyle.Fill;
            userControl.Name = "contentarea";

            this.contentPanel.Controls.Add(userControl);

            ----------------------------- In just two days, tomorrow will be yesterday.

            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