Managing settings

nismo

Member
Joined
Jun 30, 2006
Messages
18
Programming Experience
3-5
Heres what im trying to do.

I have hundreds of settings in my application, and i want a settings editor for my form.

Theres going to be about 30 categories of settings and i think i know how to go about it.



Option 1#
Have a treeview with each category. Then create 30 group boxes (one for each category) and show the correct group box based on what the user has selected in the treeview.

I do not like this way because it requires a huge select case statement which i have to maintain, and having to constantly shift group boxes around in order to add/edit settings is a pain in the ass especially since i have to be careful not to drag a group box into another one.



Option 2#
Similar to #1, except i create a usercontrol with a treeview, and it will dynamically create and show group boxes based on what category you choose. I figure this would be great because in the designer for my main app, i could place this usercontrol on my form and in design mode i would create all the categories in the treeview and when i click on a treeview item it will show the corresponding group box. This makes it easy to access my settings group boxes at design time and add/edit controls in them.



I have the usercontrol, i have a Categories property which is of type TreeNodeCollection. I can add all my categories but my problem is, in the designer, i cant click on the treeview notes - it just selects my entire usercontrol. How do i enable it so that in the designer, i can use the treeview as if it were in run mode?



Any other suggestions would be much appreciated.
 
I would suggest a form with a TreeView on it. You would then define a different UserControl class for each group of settings. When the user selects a node in the tree you would check its Tag property. If it's Nothing you create an instance of the corresponding UserControl and show it. If it's not Nothing then you show the UserControl it refers to. You would probably want to hide the current group when a new group was shown. If performance starts to degrade because of the number of controls then you may have to destroy old groups rather than hiding them.
 
I would suggest a form with a TreeView on it. You would then define a different UserControl class for each group of settings. When the user selects a node in the tree you would check its Tag property. If it's Nothing you create an instance of the corresponding UserControl and show it. If it's not Nothing then you show the UserControl it refers to. You would probably want to hide the current group when a new group was shown. If performance starts to degrade because of the number of controls then you may have to destroy old groups rather than hiding them.

The problem with this solution is the same as my original problem with option #1 - I'd still need to maintain 30 control containers (whether they are usercontrols or group boxes doesnt matter) on my form which contain all the controls. Thats my biggest issue. If i need to go back and change or add a setting, i need to drop down on the controls list in the properties window, find the right group box, and then move it into view - making sure i dont accidentally drag it into another group box. If at desgin time i could use the treeview and it would automatically display the right group box then that would be perfect.
 
It's quite easy to manage multiple overlayed controls at design time. You just don't use drag and drop. Let's say you want to have three GroupBoxes overlayed on a form. You just double-click the GroupBox in the Toolbox and one will be added to the form. You then click the form. You then double-click the GroupBox in the Toolbox again to add a second GroupBox to the form. Now click the form again. Do the same to add the third GroupBox. Because you click the form in between you are making it the selected control so the next control you add will be added to it and not the previous GroupBox.

Now you just select all three GroupBoxes in the designer and then open the Properties window. Set the Loaction and Size properties to position all three GroupBoxes on top of each other. You now have three GroupBoxes all stacked in the z-order.

To select the correct GroupBox you now have two choices:

1. Right-click the visible GroupBox and select "Send to Back". Repeat this until the GroupBox you want is visible.
2. Open the properties window and select your desired GroupBox from the drop-down list at the top. Right-click on the selection rectangle in the designer and select "Bring to Front".

It's all very easy and there's no chance of messing it up accidentally. I'd suggest that you set the Locked property of each control to True just to make sure they aren't dragged accidentally.

The issue with this is that with thirty GroupBoxes all full of controls your form may perform poorly. That's why I was suggesting creating a UserControl for each group. That way you have design time support but you wouldn't actually add them to the form until run time. That way you can ensure that only one, or at least a small number, of groups are on the form at any one time and performance will not degrade.
 
Back
Top