473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

combobox n dataset

Hi,

I have a problem, and I just cant fint a good way to solve it.
I have 3 tables in my DB
Table1
-------
IDTable1
....

Table2
-------
IDTable2
IDTable1 (forign key -> Table1)
....

Table3
-------
IDTable3
IDTable2 (forign key -> Table2)
....

Now, on form load I need to fill one combo box with data from table1.
That works good, I just create dataset, fill it with tables, and fill
combo with IDTable1.

But now,
When someone choose one IDTable1 from first combo I have to fill second
combo with data from Table2 (according to forign key
Table2.IDTable1=Table1.IDTable1)??? Also when he choose another IDTable1
from first combo, datas in second combo should also change. (same way is
for 3th combo).

Which event on combo should I use, how to fill second combo after that
event ?!?
Nov 16 '05 #1
3 4285
Dino,

You actually don't have to do anything in order to handle this scenario.
What you want to do is load the data from the three tables into one data set
(three separate tables). Once you do that, define your relationships
correctly (using the DataRelationships class, through the Relationships
property on the DataSet).

Finally, bind the combobox to the relationship, and not to the data
table, and when you change the record position in the first table (which has
the primary key), the data in the associated comboboxes will change.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dino L." <se******@gmail.com> wrote in message
news:O9**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have a problem, and I just cant fint a good way to solve it.
I have 3 tables in my DB
Table1
-------
IDTable1
...

Table2
-------
IDTable2
IDTable1 (forign key -> Table1)
...

Table3
-------
IDTable3
IDTable2 (forign key -> Table2)
...

Now, on form load I need to fill one combo box with data from table1. That
works good, I just create dataset, fill it with tables, and fill combo
with IDTable1.

But now,
When someone choose one IDTable1 from first combo I have to fill second
combo with data from Table2 (according to forign key
Table2.IDTable1=Table1.IDTable1)??? Also when he choose another IDTable1
from first combo, datas in second combo should also change. (same way is
for 3th combo).

Which event on combo should I use, how to fill second combo after that
event ?!?

Nov 16 '05 #2
i can't add an item after the datasource is set...the following code throws
an exception trying to execute the 2nd line:
cbExchange.DataSource = cb.DataSource;
cbExchange.Items.Add( "" );
cbExchange.ValueMember = "exchange_id";
cbExchange.DisplayMember = "symbol";

If i add it before the datasource, it doesn't really "stick"..as the
datasource clears all then adds the items in the datatable/dataset.
Doesn't this seem like a lot of hoops to jump thru though..should there be
an easier way? (i hope this is a bug.)
any other suggestions?

"Nicholas Paldino [.NET/C# MVP]" wrote:
Dino,

You actually don't have to do anything in order to handle this scenario.
What you want to do is load the data from the three tables into one data set
(three separate tables). Once you do that, define your relationships
correctly (using the DataRelationships class, through the Relationships
property on the DataSet).

Finally, bind the combobox to the relationship, and not to the data
table, and when you change the record position in the first table (which has
the primary key), the data in the associated comboboxes will change.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dino L." <se******@gmail.com> wrote in message
news:O9**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have a problem, and I just cant fint a good way to solve it.
I have 3 tables in my DB
Table1
-------
IDTable1
...

Table2
-------
IDTable2
IDTable1 (forign key -> Table1)
...

Table3
-------
IDTable3
IDTable2 (forign key -> Table2)
...

Now, on form load I need to fill one combo box with data from table1. That
works good, I just create dataset, fill it with tables, and fill combo
with IDTable1.

But now,
When someone choose one IDTable1 from first combo I have to fill second
combo with data from Table2 (according to forign key
Table2.IDTable1=Table1.IDTable1)??? Also when he choose another IDTable1
from first combo, datas in second combo should also change. (same way is
for 3th combo).

Which event on combo should I use, how to fill second combo after that
event ?!?


Nov 16 '05 #3
if i do the following, i can get a blank row. but man, what a kludge!

DataTable tmpDT = cb.DataSource;
DataRow nr = tmpDT.NewRow( );
tmpDT.Rows.InsertAt( nr, 0 );
tmpDT.DefaultView.Sort = "code";
cbExchange.DataSource = tmpDT; // cb.DataSource;
cbExchange.ValueMember = "exchange_id";
cbExchange.DisplayMember = "symbol";
"Nicholas Paldino [.NET/C# MVP]" wrote:
Dino,

You actually don't have to do anything in order to handle this scenario.
What you want to do is load the data from the three tables into one data set
(three separate tables). Once you do that, define your relationships
correctly (using the DataRelationships class, through the Relationships
property on the DataSet).

Finally, bind the combobox to the relationship, and not to the data
table, and when you change the record position in the first table (which has
the primary key), the data in the associated comboboxes will change.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dino L." <se******@gmail.com> wrote in message
news:O9**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have a problem, and I just cant fint a good way to solve it.
I have 3 tables in my DB
Table1
-------
IDTable1
...

Table2
-------
IDTable2
IDTable1 (forign key -> Table1)
...

Table3
-------
IDTable3
IDTable2 (forign key -> Table2)
...

Now, on form load I need to fill one combo box with data from table1. That
works good, I just create dataset, fill it with tables, and fill combo
with IDTable1.

But now,
When someone choose one IDTable1 from first combo I have to fill second
combo with data from Table2 (according to forign key
Table2.IDTable1=Table1.IDTable1)??? Also when he choose another IDTable1
from first combo, datas in second combo should also change. (same way is
for 3th combo).

Which event on combo should I use, how to fill second combo after that
event ?!?


Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Wayne Wengert | last post by:
I am trying to populate a combobox with a lisy of items. I want the 1st item to be "Make a Selection" and the following items will be names from a table in my DB (See code below). When I run the...
6
by: Omar | last post by:
When I try to databind my comboBox (specifically field "emplcode") to a filled dataset , the contents of the comboBox displays a bunch of "System.Data.DataRowView". I assume the amount of times...
3
by: Tamir Khason | last post by:
Why this does not work??? cb1 - combobox DataProvider.DataProvider.DS_BringRacks() - DataSet cb1.DataSource=DataProvider.DataProvider.DS_BringRacks().Tables; cb1.DisplayMember = "id"; ...
2
by: Hugo Lefevre | last post by:
dear, I have a form (frmlogonaccounts.cs) with a combobox, which I want to fill up with the first column of a dataset. The dataset is created in the class Login. My problem is the next : I make...
2
by: Simon Verona | last post by:
I have a combobox that is contained within a user control. Whilst the application is running, I'm attaching the combobox to a new dataset. The problem I'm getting is that the combobox doesn't...
4
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box...
1
by: fiaolle | last post by:
Hi The first set of source code is the class for a combobox in a grid, hopefully. In the second set of code we try to use the combobox class, but the grid is empty. I don't understand how this...
7
by: samoore33 | last post by:
I am trying to dynamically add items to a listbox or combobox. The items add to either, but when I look through those items, there is nothing there. If I choose an item, it shows up. Not sure...
4
by: Jerad Rose | last post by:
I'm baffled by this -- is there not a typed object used for ComboBox Items? Best I can tell, all of the methods for ComboBox that accept an Item are of type Object. Why in the world is a...
1
by: Robert Dufour | last post by:
I have a table of addresses and it contains a CountryId which points to a table of countries. The datatstructure of the Countries Lookup tables is actually created from three tables - a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.