I am having a problem with a combo box. I have three radio buttons that control the comboxes. Only one is visible. I have 4 combo boxes. The combo boxes are populated with data from a Access Database.When a user selects a item from the first combo box it then calls a stored procedure and turns the second combo box visible and so forth until the last combo box. The way I have it set right now is I have a method that gets the string from the selection in the first combo box then turns the second combobox visible and then calls another method which the repeats the first method. Problem is that the combobox does not appear until select a different radio button. When I select the first radio button again after deselcting it, it then appaears. How do I do it so that the comboboxes will dyamically appear right after each other based on the selection in the combobox? Here is a relevant code from my project.
private void GetProducColors()
{
//Misc DB calls to stored procedure Not needed to look at
//Populates the first combobox
//Gets the string selection
string strSelection = cmbProductColor.SelectedItem.ToString();
//Turns first combobox visible
this.cmbFirstColor.Visible = true;
//Send String to First Imprint Color
GetFirstImprintColors(strSelection);
}
private void GetFirstImprintColors(string strSelection)
{
}
Loading
JohnnyPosted Oct 19, 2007, 6:10 PM
MichaelPosted Oct 19, 2007, 4:50 PM
John, I am not sure I am clear on your real intent, but...
The event I used is the comboBox SelectedValueChanged. I took the code you had in your previous post and used this event to call the GetFirstBox function and make the second comboBox visible. In this way, when the otpButtonOne is checked, comboBoxOne is set up with a list of colors. comboTwo and Three are not visible. When the user selects a color, the cmbComboOne_SelectedValueChanged event is called, gets the selection text and calls GetFirstBox that sets up comboBoxTwo and makes it visible. At this point I am not sure how you want things to work, but hopefully this helps. Here's the code.
JohnnyPosted Oct 18, 2007, 9:29 PM
Here is my generic form.
namespace Combo_Test
{
public partial class Form1 : Form
{
private string m_selection;
public Form1()
{
InitializeComponent();
}
private void optButtonOne_CheckedChanged(object sender, EventArgs e)
{
this.cmbComboOne.Items.Clear();
this.cmbComboTwo.Visible = false;
this.cmbComboThree.Visible = false;
this.cmbComboOne.Text = "Select a Color";
this.cmbComboOne.Items.AddRange(new object[] { "blue" , "green", "purple" });
m_selection = this.cmbComboOne.SelectedItem.ToString();
GetFirstBox(m_selection);
}
private void optButtonTwo_CheckedChanged(object sender, EventArgs e)
{
if (optButtonTwo.Checked == true)
{
this.cmbComboOne.Items.Clear();
this.cmbComboOne.Text = "Select a Item";
this.cmbComboTwo.Visible = false;
this.cmbComboThree.Visible = false;
this.cmbComboOne.Items.AddRange(new object[] { "cars", "boats", "trains" });
}
}
public void GetFirstBox(string selection)
{
this.cmbComboTwo.Visible = true;
this.cmbComboTwo.Items.Clear();
this.cmbComboTwo.Text = "Select a Second Item";
this.cmbComboTwo.Items.AddRange(new object[] { "yellow", "red", "orange" });
}
}
}
JohnnyPosted Oct 18, 2007, 5:05 PM
What event handler would you use for the second question?
MichaelPosted Oct 18, 2007, 4:52 PM
Sorry that did not work for you may be I do not understand the problem.
I do not see it in some test code I tried. I copied your code snipit into a form with three CBs only one visible. I put some bogus data in that CB. I then connected the visible CB to an event handler for event SelectedValueChanged. In the event handler I called your GetProducColors(). The second CB became visible. But of course I do not have the database connection etc.
An event handler could be used to do the something that you want from your second question.
JohnnyPosted Oct 18, 2007, 2:30 PM
if anything is selected from the combobox do something?
MichaelPosted Oct 17, 2007, 4:51 PM