Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] C# "PropertyTree" like control

Started by ver_T_ex Feb 16, 2006 at 8:30 PM 28 replies 9k views
Original Post
ver_T_ex
ver_T_ex
Hi guys, I've been wondering all night how to code an option dialog like the "Tools->Options..." in the Visual Studio .net environment in which the user can decide which dialog he wants to see by choosing in the treeview and the "under-dialogs" next to the tree view changes. The only thing I found was: http://www.codeproject.com/cs/miscctrl/propertytree.asp but I don't think every program in which I saw these features uses this libary. I would be so happy if you could help me. thanks!
Washu
Washu
TreeView control.
In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
Nypyren
Nypyren
Ok, without going into too much detail, here's the general idea of how that dialog works:

You have your custom UserControl or Form. It has a TreeView, a Splitter, and a Panel. Each time the selected item in the TreeView changes, your UserControl handles an event and replaces the Panel with a different Panel.

Each Panel then contains whatever controls you want to put in it.


That project on CodeProject looks like it does all of that, and provides a way to edit the contents of each Panel in the form designer, which is nice, but not a necessity.
ver_T_ex
ver_T_ex
@Washu - sorry if I didn't explain myself clearly - TreeViews are not the problem - the problem is, how to load the "underdialogs" next to the TreeView dynamically.

So I found the PanelControl and I tried all evening how to load a form to this panel because panel controls seem only work with controls.

@Nypyren I understand the panel thing, but for what do I need the Splitter ?

Thanks for your help guys!
Bob Janova
Bob Janova
The splitter is just for display niceness, allowing you to change how wide the treeview is.
ver_T_ex
ver_T_ex
Maybe I asked the wrong way. Is there a rectangular control that can be initialized with a form / can hold a form ? The Dialog in a Dialog principe!
Arild Fines
Arild Fines
Quote:
Original post by ver_T_ex
Maybe I asked the wrong way. Is there a rectangular control that can be initialized with a form / can hold a form ? The Dialog in a Dialog principe!

No, a Form cannot be contained in anything else. It's strictly a top-level control. If you want something to put into other controls, use f.ex a Panel.

--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
ver_T_ex
ver_T_ex
But by then I can't design these dialogs in the editor.
Nearly every good program supporting an option dialog uses this way of presenting data. There gotta be an easy way to do that otherwise everyone would use Tabs ;)

Do I have to design the dialog in the Editor, then copy the code and and add these controls to a panel. That would be not so comfortable.

Bob Janova
Bob Janova
I have a similar issue with a program I wrote recently. What I do is design the form using the draggy-droppy editor, and then change the line at the top ...

public class MyCoolTab : Panel
(not Form any more)

If you need to edit it again, just change it back for a bit.
davepermen
davepermen
are user controls an option? you can create them in the wysiwyg editor.
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia
My Page davepermen.net | My Music on Bandcamp and on Soundcloud
Arild Fines
Arild Fines
Quote:
Original post by ver_T_ex
But by then I can't design these dialogs in the editor.

You can design any kind of control in the forms designer. In your case, a user control or a panel would do the trick.

--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
ver_T_ex
ver_T_ex
But the panel is static isn't it ? I can design one layout within the designer BUT I want different controls in the panel, changing when the users click on other treeView nodes.

Visual Studio -> Tools -> Options

Something like that. This Options Dialog is not static at all, so there is, as far as I know, no way beside Tabs to do the changing dialog controls...
sorry that it is so difficult to explain....
Arild Fines
Arild Fines
Quote:
Original post by ver_T_ex
But the panel is static isn't it ? I can design one layout within the designer BUT I want different controls in the panel, changing when the users click on other treeView nodes.

So you swap out one panel with another. Associate a panel with each treenode, using the TreeNode.Tag property, and when a node is selected, get the associated panel and set it as the displayed one.

private void TreeView1_AfterSelect(System.Object sender,     System.Windows.Forms.TreeViewEventArgs e){   Panel panel = e.Node.Tag as Panel;   if ( panel != null )   {      this.rightPane.Controls.Clear();      this.rightPane.Controls.Add( panel );      panel.Dock = DockStyle.Fill;   }}
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
janoside
janoside
Quote:
No, a Form cannot be contained in anything else. It's strictly a top-level control.


A form can be contained within another form through MDI.
-janoside [Firestorm Engine]
ver_T_ex
ver_T_ex
Arild Fines Wow, this is the kind of solution I was looking for. I'm checking that but thanks for your help! :)

You are talking about swapping the panels. But I'm wondering where these panels come from? Let's say I have an array of panels, each with the same size (big next to the TreeView) each with different controls in it. By executing your code with some slight modifications, the panel are being swapped and only one is displayed ?

Maybe it is the c++ polluted mind of mine that is complicating this whole thing! I always have the c++'isch way in mind, designing a modeless dialog, and loading it into a control in another dialog. But C# and C++, both are windows so I thought you could transfer these things...

[Edited by - ver_T_ex on February 18, 2006 6:36:37 PM]
Arild Fines
Arild Fines
Quote:
Original post by janoside
Quote:
No, a Form cannot be contained in anything else. It's strictly a top-level control.


A form can be contained within another form through MDI.

Good point, I didn't think of that. However, it's not really relevant here, and MDI's sort of fallen out of grace anyway...

--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Arild Fines
Arild Fines
Quote:
Original post by ver_T_ex
You are talking about swapping the panels. But I'm wondering where these panels come from? Let's say I have an array of panels, each with the same size (big next to the TreeView) each with different controls in it.

Another question would be: where are the tree nodes coming from? You can initialize the panels at the same time you create the tree nodes:

TreeNode configFooNode = new TreeNode();configFooNode.Tag = new ConfigFooPanel();TreeNode configBarNode = new TreeNode();configBarNode.Tag = new ConfigBarPanel();this.treeView.Nodes.Add( configFooNode );this.treeView.Nodes.Add( configBarNode );



Quote:

By executing your code with some slight modifications, the panel are being swapped and only one is displayed ?

That's the idea, yes.

--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
ver_T_ex
ver_T_ex
Okey everything clear so far, by the way, thanks for your very good help!

Just a last question I'm not sure about. Panel control means I have to add Controls via the .Add() method. This means I can design the content of a panel once, but what if I want to have different designs ? Design them in an empty form, copy the code and insert it where I need it ( for example to that part that is handling the different Nodes) ...unfortunately I'm not used to that technic, because I'm quite new to C# (coming from C++ as you might have read)

Well I'm wondering now how can I prepare these panels which I change after selection ? I'd prefer designing them in the IDE of visual studio. That's the last piece of the puzzle. :)

[Edited by - ver_T_ex on February 19, 2006 10:24:14 AM]
Arild Fines
Arild Fines
Quote:
Original post by ver_T_ex
Okey everything clear so far, by the way, thanks for your very good help!

Just a last question I'm not sure about. Panel control means I have to add Controls via the .Add() method. This means I can design the content of a panel once, but what if I want to have different designs ? Design them in an empty form, copy the code and insert it where I need it ( for example to that part that is handling the different Nodes) ...unfortunately I'm not used to that technic, because I'm quite new to C# (coming from C++ as you might have read)

Well I'm wondering now how can I prepare these panels which I change after selection ? I'd prefer designing them in the IDE of visual studio. That's the last piece of the puzzle. :)

Not really sure what you're asking. Just add the panel controls to your project, design them in the designer and attach them to the treeview the way I showed earlier. The designer lets you design panels or user controls just fine, it's not restricted to designing forms.

--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
ver_T_ex
ver_T_ex
But How am I gonna design panel2 and panel3 and panel4 which I'm assigning to Node2 Node3 and Node4.... I can't overlay them, I mean I want them all at the same position, meaning that they would be all above in the designer. I don't know a way to do this....I'm not sure how to explain it else...

;) I'm feeling stupid somehow... Anyway: another possibility is to just have one panel and change the controls in it when someone selects another node -> question then: how to design the arrangement of the controls in the panel then ? The other way would be the one described above...

[Edited by - ver_T_ex on February 21, 2006 11:10:05 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.