Click to See Complete Forum and Search --> : Advise on best way to do this.


Ctwizzy
March 8th, 2005, 04:57 PM
I have a Dialog which houses all my preferences that can be changed.
On save it saves all the information to an XML.

I am having trouble figuring out a good way to do this:

There is to be a setting which can have multiple entires.
So for example say I am trying to set the levels of users.
Level1 - Admin
Level2 - Asst Admin
Level3 - Mgmt
Level4 - user

if the user goes into the preferences these 4 will be displayed to them. But say they want more levels they should be able to add more in, or if they want to remove, they can, or rename.

The way I was planning on implementing this is:
it would show 'X' textbox's to the user with the levels
if they press the 'Add button' a new textbox with a blank entry would be created under the previous and they can enter in and save.
next to the textbox's would be a checkbox, if they check the box and press delete the textboxs with a checkbox with a check are deleted.
Rename would be simply done by changing the text in the textbox.

Upon exiting the dialog it resaves the settings.

Can anyone think of a better way to approach this?

Ctwizzy
March 16th, 2005, 12:09 PM
Maybe an ArrayList of textbox's ugh, this seems like a weird way of doing this.

cilu
March 16th, 2005, 01:51 PM
This looks ugly to me. Change the number of controls dinamically... :sick: What someone creates 10 or 20 user levels? It's probably unlikely, bu what if? Will you have space for all?

I would suggest a list box, or perhaps a checked list box. You can add or remove any items to/from it without woring for problems with form space.

Just my 2 cents.

Ctwizzy
March 16th, 2005, 03:11 PM
Ok so a list/combo is better.

So let them enter stuff in and then just go thru the collection parsing out the differences?

Ctwizzy
March 16th, 2005, 06:16 PM
Ok so like this?


//reading
//Determine # of positions
Int32 positions = config.Read("numPositions");
for (Int32 index = 1; index <= positions; index++)
{
//positions would be listed as position1, position2, position3, position4 etc
this.lstBoxPositions.Items.Add(config.Read("position" + index)); }


then for writing

//this doesnt work as listBox has no length property or no easy way of //finding out how many entries are in it
config.Write("numPositions", this.lstBoxPositions.length);
for (Int32 index = 0; index <= this.lstBoxPositions.length; index++)
{
config.Write("position" + (index + 1), this.lstBoxPositions.Items[index].ToString());
}


Only problem with this I can see is that if they had 10 and erased 5, 5 would still be in the xml file, just wouldnt be used. I guess I could just

for (Int32 index = lstBoxPositions.Length(); index < oldLength; index++)
{
config.Write("position" + (index + 1), "");
}


this way the lines would still be there but the text would be gone. Would have to figure out a way to erase the lines in the xml files otherwise.

if anyone can think of a cleaner way to do this, let me know thanks.

Ctwizzy
March 16th, 2005, 06:22 PM
ok figured out num of items in listbox.

this.lstBoxPositions.Items.Count