By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,009 Members | 1,487 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,009 IT Pros & Developers. It's quick & easy.

Binding a ComboBox in a Windows Form to a Hierarchical DataSet

P: n/a
I have two tables in a parent-child relationship. Details on the tables are
as shown below:

Table1
-------
Item_ID (primary key)
Item_Owner (foreign key to Table2)

Table2
-------
Owner_ID (primary key)
Owner_Name
I wish to display, on a form designed for maintenance of the data in Table1,
a combobox which displays owner names (Table2.Owner_Name), but returns as
its bound ValueMember the item owner's ID (Table1.Item_Owner). Can I do
it?

Thanks!

--
Greg Dunn

Nov 15 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi Greg,

AFAIK you can't. Binding is against flat table.
However, I am bit confused.
You want to show parent record name and return the child id?
Didn't you mean to display Owner_Name and return Owner_Id (as it is equeal
to Item_Owner)?

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com

"Greg Dunn" <My*****@gregdunn.com> wrote in message
news:SjmEb.424031$ao4.1359279@attbi_s51...
I have two tables in a parent-child relationship. Details on the tables are as shown below:

Table1
-------
Item_ID (primary key)
Item_Owner (foreign key to Table2)

Table2
-------
Owner_ID (primary key)
Owner_Name
I wish to display, on a form designed for maintenance of the data in Table1, a combobox which displays owner names (Table2.Owner_Name), but returns as
its bound ValueMember the item owner's ID (Table1.Item_Owner). Can I do
it?

Thanks!

--
Greg Dunn

Nov 15 '05 #2

P: n/a
> Didn't you mean to display Owner_Name and return Owner_Id (as it is equeal
to Item_Owner)?
Since, as you note, the Owner_ID will equal the Item_Owner, it really
doesn't matter which of them is returned. But Table1.Item_Owner is the
column to which I would like the control to be bound.
AFAIK you can't. Binding is against flat table.
I haven't found a way to do it, either. It seems like a nasty limitation,
though, since it forces me a choice among several things, none of which I
want to choose:

1. Foregoing the benefits of data binding in the form, or
2. Not using abstract primary keys, or
3. Denormalizing the database.

--
Greg Dunn
"Miha Markic" <miha at rthand com> wrote in message
news:eo**************@tk2msftngp13.phx.gbl... Hi Greg,

AFAIK you can't. Binding is against flat table.
However, I am bit confused.
You want to show parent record name and return the child id?
Didn't you mean to display Owner_Name and return Owner_Id (as it is equeal
to Item_Owner)?

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com

"Greg Dunn" <My*****@gregdunn.com> wrote in message
news:SjmEb.424031$ao4.1359279@attbi_s51...
I have two tables in a parent-child relationship. Details on the tables

are
as shown below:

Table1
-------
Item_ID (primary key)
Item_Owner (foreign key to Table2)

Table2
-------
Owner_ID (primary key)
Owner_Name
I wish to display, on a form designed for maintenance of the data in

Table1,
a combobox which displays owner names (Table2.Owner_Name), but returns as its bound ValueMember the item owner's ID (Table1.Item_Owner). Can I do it?

Thanks!

--
Greg Dunn


Nov 15 '05 #3

P: n/a
Hi Greg,

Ah sorry, you are after a lookup, right.
Set ComboBox' ValueMamber and DisplayMember to a column from Table2 and
DataSource to Table2
Go to DataBindings and bind Selected Value to Table1.Item_Owner.

That should enable combobox to act like lookup.

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
"Greg Dunn" <My*****@gregdunn.com> wrote in message
news:cbnEb.424304$ao4.1359496@attbi_s51...
Didn't you mean to display Owner_Name and return Owner_Id (as it is equeal
to Item_Owner)?


Since, as you note, the Owner_ID will equal the Item_Owner, it really
doesn't matter which of them is returned. But Table1.Item_Owner is the
column to which I would like the control to be bound.
AFAIK you can't. Binding is against flat table.


I haven't found a way to do it, either. It seems like a nasty limitation,
though, since it forces me a choice among several things, none of which I
want to choose:

1. Foregoing the benefits of data binding in the form, or
2. Not using abstract primary keys, or
3. Denormalizing the database.

--
Greg Dunn
"Miha Markic" <miha at rthand com> wrote in message
news:eo**************@tk2msftngp13.phx.gbl...
Hi Greg,

AFAIK you can't. Binding is against flat table.
However, I am bit confused.
You want to show parent record name and return the child id?
Didn't you mean to display Owner_Name and return Owner_Id (as it is equeal to Item_Owner)?

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com

"Greg Dunn" <My*****@gregdunn.com> wrote in message
news:SjmEb.424031$ao4.1359279@attbi_s51...
I have two tables in a parent-child relationship. Details on the
tables are
as shown below:

Table1
-------
Item_ID (primary key)
Item_Owner (foreign key to Table2)

Table2
-------
Owner_ID (primary key)
Owner_Name
I wish to display, on a form designed for maintenance of the data in

Table1,
a combobox which displays owner names (Table2.Owner_Name), but returns

as its bound ValueMember the item owner's ID (Table1.Item_Owner). Can I do it?

Thanks!

--
Greg Dunn



Nov 15 '05 #4

P: n/a
Greg,

You want to fill your Owner table with all the valid vlaues it would be
(complete table scan?) just use a Data Adapter to fill it or whatever you
want.

Then, on your bindings, you want to bind your combo boxes SelectedValue to
your Table1.Item_Owner Property.

This should take care of it.

and on yoru combo box, set your display member to Owner_name and your
valuemember to OwnerID. Thats all it takes.

peace,
cJ
"Greg Dunn" <My*****@gregdunn.com> wrote in message
news:SjmEb.424031$ao4.1359279@attbi_s51...
I have two tables in a parent-child relationship. Details on the tables are as shown below:

Table1
-------
Item_ID (primary key)
Item_Owner (foreign key to Table2)

Table2
-------
Owner_ID (primary key)
Owner_Name
I wish to display, on a form designed for maintenance of the data in Table1, a combobox which displays owner names (Table2.Owner_Name), but returns as
its bound ValueMember the item owner's ID (Table1.Item_Owner). Can I do
it?

Thanks!

--
Greg Dunn

Nov 15 '05 #5

P: n/a
Ah...very easy. Many thanks!

--
Greg Dunn
"Miha Markic" <miha at rthand com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi Greg,

Ah sorry, you are after a lookup, right.
Set ComboBox' ValueMamber and DisplayMember to a column from Table2 and
DataSource to Table2
Go to DataBindings and bind Selected Value to Table1.Item_Owner.

That should enable combobox to act like lookup.

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
"Greg Dunn" <My*****@gregdunn.com> wrote in message
news:cbnEb.424304$ao4.1359496@attbi_s51...
Didn't you mean to display Owner_Name and return Owner_Id (as it is equeal to Item_Owner)?


Since, as you note, the Owner_ID will equal the Item_Owner, it really
doesn't matter which of them is returned. But Table1.Item_Owner is the
column to which I would like the control to be bound.
AFAIK you can't. Binding is against flat table.


I haven't found a way to do it, either. It seems like a nasty limitation,
though, since it forces me a choice among several things, none of which I want to choose:

1. Foregoing the benefits of data binding in the form, or
2. Not using abstract primary keys, or
3. Denormalizing the database.

--
Greg Dunn
"Miha Markic" <miha at rthand com> wrote in message
news:eo**************@tk2msftngp13.phx.gbl...
Hi Greg,

AFAIK you can't. Binding is against flat table.
However, I am bit confused.
You want to show parent record name and return the child id?
Didn't you mean to display Owner_Name and return Owner_Id (as it is equeal to Item_Owner)?

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com

"Greg Dunn" <My*****@gregdunn.com> wrote in message
news:SjmEb.424031$ao4.1359279@attbi_s51...
> I have two tables in a parent-child relationship. Details on the tables are
> as shown below:
>
> Table1
> -------
> Item_ID (primary key)
> Item_Owner (foreign key to Table2)
>
> Table2
> -------
> Owner_ID (primary key)
> Owner_Name
>
>
> I wish to display, on a form designed for maintenance of the data in
Table1,
> a combobox which displays owner names (Table2.Owner_Name), but

returns as
> its bound ValueMember the item owner's ID (Table1.Item_Owner). Can
I do
> it?
>
> Thanks!
>
> --
> Greg Dunn
>
>
>



Nov 15 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.