944,134 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 2843
  • C# RSS
Oct 17th, 2007
0

Problem with Form and Combox selections

Expand Post »
I have a Form that has 3 radio buttons grouped together. I have a default combobox selected on the form. When a user selects a item from the combo box a new combo box appears that is populated from the data in a access DB. Problem is that right now when you select a selection the new combo box does not appear. It instead appears when you select one of the other radio buttons then go back to the original ComboBox.

Here is the code.

First Part is the radio button which calls the next function

C# Syntax (Toggle Plain Text)
  1. private void optProductColor_CheckedChanged(object sender, EventArgs e)
  2. {
  3. try
  4. {
  5. if (optProductColor.Checked == true)
  6. {
  7. this.lblProductColor.Visible = true;
  8. this.cmbProductColor.Visible = true;
  9. this.lblCustomerType.Visible = false;
  10. this.cmbCustomerType.Visible = false;
  11.  
  12. GetProductColors();
  13. }
  14.  
  15. }
  16. catch (Exception ex)
  17. {
  18. Console.WriteLine(ex.Message);
  19. }
  20.  
  21. }
Here is the next function

C# Syntax (Toggle Plain Text)
  1. private void GetProductColors()
  2. {
  3. try
  4. { //DB calls to Stored Procedure
  5. //Read the DB into our ComboBox
  6. while (oleDbDataReader1.Read() == true)
  7. {
  8. this.cmbProductColor.Items.Add(oleDbDataReader1.GetString(0));
  9. }
  10. }
  11. catch (Exception ex)
  12. {
  13. Console.WriteLine(ex.Message);
  14. }
  15. finally
  16. {
  17. oleDbConnection1.Close();
  18. }
  19.  
  20. //Get Selection from Combo Box
  21. string strSelection = cmbProductColor.SelectedItem.ToString();
  22. //Make next combobox visible
  23. this.cmbFirstColor.Visible = true;
  24.  
  25. //Send String to First Imprint Color
  26. GetFirstImprintColors(strSelection);
  27. }
This calls the next function which is not displayed until I leave the radio button and then come back

C# Syntax (Toggle Plain Text)
  1. private void GetFirstImprintColors(string strSelection)
  2. {
  3. try
  4. {
  5. //See if DB is open
  6. //DB calls
  7. //Read the DB into our ComboBox
  8. while (oleDbDataReader1.Read() == true)
  9. {
  10. this.cmbFirstColor.Items.Add(oleDbDataReader1.GetString(0));
  11. }
  12. }
  13. catch (Exception ex)
  14. {
  15. Console.WriteLine(ex.Message);
  16. }
  17. finally
  18. {
  19. oleDbConnection1.Close();
  20. }
  21.  
  22. }

How do I make each combo box visible after a selection is selected? Like a chain reaction?

Thanks
Last edited by blazted; Oct 17th, 2007 at 1:04 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
blazted is offline Offline
17 posts
since Oct 2006
Oct 18th, 2007
0

Re: Problem with Form and Combox selections

I have been trying to get this work and so far the only way i cna get this to work is if I use a If else statement that is dependent on the a user selection. But since I do not know the values of the combo box prior to the first entry I cannot assiga if else statement.

Is there any way to do a statment with a combo box on these osrt of lines?

if(combobox.selectedItem() = anything)
do this?

Since I do not know the argument prior to the selection I need the selected Item to be == to anything. Is there a way to do this?

Thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
blazted is offline Offline
17 posts
since Oct 2006
Oct 26th, 2007
0

Re: Problem with Form and Combox selections

ok, in your GetProductsColor() you are populating the combo cmbProductColor - right? I would suggest doing cmbProductColor.Items.Clear(); before adding new stuff or you will append the values without getting rid of old values.

Later in the same function you are capturing selected item, well, the selected item is null because your user did not have a chance to actually seleect anything as of yet. This means that your strSelection is null. and when you call GetFirstImprintColors you are actually passing null to it, but it does not matter since you are not usign that string in the function anywho.

I would suggest following approach:

on load - populate both combo boxes, second combo visible = false;

go to the combo1_SelectedIndexChanged and specify that once the idex is changed, combo 1.visible = false and combo 2.visible is true;

go to the combo2_SelectedIndexChanged and do combo 2.visible = false; combo 1.visible = true.

Above events will ensure that once your user selects anything in the combo box 1, combo box 1 is now invisible and combo box 2 is visible. When user selects anything in combo box 2, combo 2 is invisible and combo 1 is visible

hope this helps

P.S. is this homework or something?
Reputation Points: 12
Solved Threads: 1
Newbie Poster
tostrinj is offline Offline
20 posts
since Jul 2007
Oct 27th, 2007
0

Re: Problem with Form and Combox selections

Click to Expand / Collapse  Quote originally posted by tostrinj ...
ok, in your GetProductsColor() you are populating the combo cmbProductColor - right? I would suggest doing cmbProductColor.Items.Clear(); before adding new stuff or you will append the values without getting rid of old values.

Later in the same function you are capturing selected item, well, the selected item is null because your user did not have a chance to actually seleect anything as of yet. This means that your strSelection is null. and when you call GetFirstImprintColors you are actually passing null to it, but it does not matter since you are not usign that string in the function anywho.

I would suggest following approach:

on load - populate both combo boxes, second combo visible = false;

go to the combo1_SelectedIndexChanged and specify that once the idex is changed, combo 1.visible = false and combo 2.visible is true;

go to the combo2_SelectedIndexChanged and do combo 2.visible = false; combo 1.visible = true.

Above events will ensure that once your user selects anything in the combo box 1, combo box 1 is now invisible and combo box 2 is visible. When user selects anything in combo box 2, combo 2 is invisible and combo 1 is visible

hope this helps

P.S. is this homework or something?
Thank You but I managed to solve it.

No it is not homework, I simply have never really worked with Forms before and I have never really done c# as well so this is very new to me. The more I work it the more I like it though and am amazed at how fast it is to both pick up and how much flexibility it has. I have always dreaded forms but this is great. A lot of the small things though still get to me as I am not sure of how to use thier properties.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
blazted is offline Offline
17 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: ArrayList from something other than primitives
Next Thread in C# Forum Timeline: small keylogger question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC