Hey guys just signed up to this site as it has helped me a lot with my first project so far.
however I've hit a wall, in my program I have got 3 combo boxes, 1 is the main one and I need it to effect the options you get a choice of in the others, for example if you select A in the main combo box then in the second one you should have a choice of b or c where as if you select D in the main combo box then in the second one you should have a choice of e or f...if you get me.
and finally a user has to fill out a form using drop down menus, is there anyway you can save the options so when they reload that window later on it loads the options previously chosen.
cheers in advance
Combo boxes and saving
Started by Halfie44, Jun 14 2010 02:11 PM
20 replies to this topic
#1
Posted 14 June 2010 - 02:11 PM
|
|
|
#2
Posted 14 June 2010 - 03:24 PM
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.
Science is only an educated theory, which we cannot disprove.
#3
Posted 14 June 2010 - 09:25 PM
//If used selects something else in first comboBox
private void checkBox1_selectedIndexChanged(sender e, Something x)
{
//Ups, please replace checkBox with comboBox :D
switch (checkBox1.Text)
{
case "A" : {
checkBox2.Items.Clear();
checkBox2.Items.Add("A-2");
checkBox2.Items.Add("B-2");
break;
}
case "B": {
checkBox2.Items.Clear();
checkBox2.Items.Add("C-2");
checkBox2.Items.Add("D-2");
break;
}
//etc.. and so on
}
What you are doing is checking what you have in te first combo box, and adding items into the others.
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics
#4
Posted 15 June 2010 - 03:35 AM
I think he wants something similar to a Combobox used for Selecting
Country
State
City.
where ,on selecting USA from country you would have the underlying states of USA in State combobox
Country
State
City.
where ,on selecting USA from country you would have the underlying states of USA in State combobox
#5
Posted 15 June 2010 - 04:02 AM
Goku thats what im looking for exactly!
Is the code davide put similar to that? I will give it a blast later to see what i get.
I need to learn so :)
any help would be great thouhh cheers
Is the code davide put similar to that? I will give it a blast later to see what i get.
I need to learn so :)
any help would be great thouhh cheers
#6
Posted 15 June 2010 - 07:29 AM
right guys Ive given it a go and well it doesn't work :/ however im getting no errors so i think im doing something wrong
Code is below in the link
Glowfoto :: Photo Sharing
Code is below in the link
Glowfoto :: Photo Sharing
#7
Posted 15 June 2010 - 09:23 AM
Halfie44 said:
right guys Ive given it a go and well it doesn't work :/ however im getting no errors so i think im doing something wrong
Code is below in the link
Glowfoto :: Photo Sharing
Code is below in the link
Glowfoto :: Photo Sharing
1. Post your code here in [ code] tags [/ code]
2. Double click on comboBox1 and paste the code in the method that is created.
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics
#8
Posted 15 June 2010 - 09:23 AM
Also, make sure the cases match.
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics
#9
Posted 15 June 2010 - 10:03 AM
code tags always come in handy. :) I dont know what i'd do without them
#10
Posted 15 June 2010 - 07:44 PM
Right guys just tried it as i cant sleep :)
and thanks Davide it all makes sense now....it seems so simple..well it is now :)
However problem
the clear seems to happen but then it doesn't readd until you've chosen another option
for example using davide's code
if you choose A in comboBox1 then comboBox2 is blank
then when you choose B in comboBox1 then in comboBox2 it shows A-2 and B-2 rather than C-2 and D-2
so like the second comboBox is always a step behind, tried to play around with it..but no luck :/
and thanks Davide it all makes sense now....it seems so simple..well it is now :)
However problem
the clear seems to happen but then it doesn't readd until you've chosen another option
for example using davide's code
if you choose A in comboBox1 then comboBox2 is blank
then when you choose B in comboBox1 then in comboBox2 it shows A-2 and B-2 rather than C-2 and D-2
so like the second comboBox is always a step behind, tried to play around with it..but no luck :/
Edited by Halfie44, 15 June 2010 - 08:19 PM.
#11
Posted 18 June 2010 - 02:21 AM
bump
#12
Posted 22 June 2010 - 01:42 PM
I don't quite understand your problem... but this is how I would do it:
Remember the index of a comboBox starts a 0 so the first selection is not 1 is 0 there for if you select United States the first choice your selected index is 0 not 1. ;)
If you need more help I can try to explain more.
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex == 0)//If United State's
{
comboBox2.Items.Clear();
comboBox2.Items.Add("Iowa");
comboBox2.Items.Add("New York");
comboBox2.Items.Add("Florida");
} else if (comboBox1.SelectedIndex == 1)//Canada
{
comboBox2.Items.Clear();
comboBox2.Items.Add("SomeWhere");
comboBox2.Items.Add("another");
comboBox2.Items.Add("blah");
}
}You would set your collection for the comboBox to United States, Canada and what ever others you wanted then if you selected United states or Canada then it would change comboBox2's choice's, hope you get it. :)Remember the index of a comboBox starts a 0 so the first selection is not 1 is 0 there for if you select United States the first choice your selected index is 0 not 1. ;)
If you need more help I can try to explain more.
Edited by CommittedC0der, 22 June 2010 - 02:39 PM.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.
Science is only an educated theory, which we cannot disprove.


Sign In
Create Account


Back to top









