Solved

Dynamic Combo Box

Posted on 2003-10-25
9
1,144 Views
Last Modified: 2009-07-29
Greetings to everyone,

I have 3 Combo Boxes on a C# form. All the data for those 3 ComboBox are popullated from an Oracle table. I want these3 ComboBox are dynamic linked to each other. That means, if I select another item in ComboBox1, the item in ComboBox2 will be changes to those associates with ComboBox1. Same to ComboBox3 and it depends on the item on ComboBox2.

I use the following code to fill ComboBox1.

      foreach (DataRow myRow in MyDataSet3.Tables[0].Rows)
                  {
                        campus.Items.Add(myRow["Region_code"]);
                  }

I know I need to modified the code for ComboBox1.TextChange. But need more details info.
Thanks in advance.

-Mark
0
Comment
Question by:mrong
  • 4
  • 3
9 Comments
 

Author Comment

by:mrong
ID: 9620691
Please ignore this question. I have found the solution by myself. I will post it by next Monday.

Thanks.
0
 
LVL 20

Accepted Solution

by:
TheAvenger earned 100 total points
ID: 9620692
OK, you have to make several things.

1. Create a dataset with 3 tables inside. In order to do this, the easiest way is to create a data adapter for each of your 3 tables, then select the 3 data adapters, right click and select generate dataset
2. When you have the dataset with the three tables, open it in design mode (it will be in your project) and add relations just like you would do this in the physical database - primary key and foreign key
3. On your combo boxes, select the following values in the properties window:
- Combo box 1: data source: the dataset.table1
- Combo box 2: data source: the dataset.table1.table2 (note that dataset.table2 will also be available but you MUST select dataset.TABLE1.TABLE2)
- Combo box 3: data source: the dataset.table1.table2.table3 - the same trick applies here

Now select values for the display member for every combo box to what exactly you want to show in the combo boxes (to see). You can also play with the value member to select which column from the table to give you the selected values.

If you have further questions, give it a try and ask.
0
 

Author Comment

by:mrong
ID: 9620693
Hi TheAvenger,

Thank you anyway:)

Mark
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:mrong
ID: 9626797
All you need to do is modified the code for SelectedIndexChanged. Here is my code, but you might find other better way to do it.

private void zone_SelectedIndexChanged(object sender, System.EventArgs e)
            {
                  bldg.Items.Clear();
                  
                  string sql4;
                  DataSet MyDataSet5 = new DataSet();  
                  sql4 = "SELECT DISTINCT BLDG";
                  sql4 += " FROM ROOT.AE_S_BLD_C";
                  sql4 += " WHERE REGION_CODE =('"+campus.Text+"') AND FAC_ID=('"+zone.Text+"')";
            sql4 += " ORDER BY BLDG";

                  OleDbConnection myConn4 = oleDbConnection1;  
                  OleDbCommand myComm4 = new OleDbCommand();
                  myComm4.Connection = myConn4;
                  myComm4.CommandText = sql4;

                  OleDbDataAdapter myAdap4 = new OleDbDataAdapter(myComm4);
                  myAdap4.Fill(MyDataSet5);
           
                  
                  
                  foreach (DataRow myRow in MyDataSet5.Tables[0].Rows)
                  {
                  
                        bldg.Items.Add(myRow["BLDG"]);

                  }

                  
                  myConn4.Close();
            }
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 9626840
The way I showed you is much more '.NET like' and is also much more efficient if I start playing with the combo boxes. It also needs only one connection to the database
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 9629209
I have supplied an answer that solves the problem the moment when mrong decided to stop it. I have also explained what is the added value and advantage of my solution over the one he presented. On my opinion the question should not be closed with PAQing as a good solution that can be used by the author was supplied.
0
 

Author Comment

by:mrong
ID: 9633396
I haven't got a chance to try TheAvenger's solution and I am working on something else. Please give me a couple of days to do so. I have no problem for giving points to the people who provide the best solution.

Thanks.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
dynamic menu in asp.net c# 11 31
cs.Designer Issue 2 20
Handle null when using linq in this line 1 20
bulid json format 3 21
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now