| | |
Problem with Form and Combox selections
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2006
Posts: 17
Reputation:
Solved Threads: 0
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
Here is the next function
This calls the next function which is not displayed until I leave the radio button and then come back
How do I make each combo box visible after a selection is selected? Like a chain reaction?
Thanks
Here is the code.
First Part is the radio button which calls the next function
C# Syntax (Toggle Plain Text)
private void optProductColor_CheckedChanged(object sender, EventArgs e) { try { if (optProductColor.Checked == true) { this.lblProductColor.Visible = true; this.cmbProductColor.Visible = true; this.lblCustomerType.Visible = false; this.cmbCustomerType.Visible = false; GetProductColors(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
C# Syntax (Toggle Plain Text)
private void GetProductColors() { try { //DB calls to Stored Procedure //Read the DB into our ComboBox while (oleDbDataReader1.Read() == true) { this.cmbProductColor.Items.Add(oleDbDataReader1.GetString(0)); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { oleDbConnection1.Close(); } //Get Selection from Combo Box string strSelection = cmbProductColor.SelectedItem.ToString(); //Make next combobox visible this.cmbFirstColor.Visible = true; //Send String to First Imprint Color GetFirstImprintColors(strSelection); }
C# Syntax (Toggle Plain Text)
private void GetFirstImprintColors(string strSelection) { try { //See if DB is open //DB calls //Read the DB into our ComboBox while (oleDbDataReader1.Read() == true) { this.cmbFirstColor.Items.Add(oleDbDataReader1.GetString(0)); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { oleDbConnection1.Close(); } }
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.
•
•
Join Date: Oct 2006
Posts: 17
Reputation:
Solved Threads: 0
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
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
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?
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?
===========================
can you repeat the part of the stuff where you said all about the things?
can you repeat the part of the stuff where you said all about the things?
•
•
Join Date: Oct 2006
Posts: 17
Reputation:
Solved Threads: 0
•
•
•
•
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?
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.
![]() |
Similar Threads
- I have a form problem (HTML and CSS)
- form freezes up (Visual Basic 4 / 5 / 6)
- vb to web form (Visual Basic 4 / 5 / 6)
- "reply-to" Outlook Express problem (Computer Science)
- Automatic email reply to Form (Site Layout and Usability)
- Problem :?: (C#)
- help with creating form counter (PHP)
- owner form display problem (VB.NET)
- Problem with moving integers to a single formatted string (C)
- Great problem in VC++ (C++)
Other Threads in the C# Forum
- Previous Thread: ArrayList from something other than primitives
- Next Thread: small keylogger question
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access algorithm array barchart bitmap box buttons c# chat check checkbox class client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees draganddrop drawing encryption enum event excel file files form format forms ftp function gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox pixelinversion post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml





