PC Review


Reply
Thread Tools Rate Thread

Binding a ComboBox in a Windows Form to a Hierarchical DataSet

 
 
Greg Dunn
Guest
Posts: n/a
 
      18th Dec 2003
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



 
Reply With Quote
 
 
 
 
Miha Markic
Guest
Posts: n/a
 
      18th Dec 2003
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" <(E-Mail Removed)> 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
>
>
>



 
Reply With Quote
 
 
 
 
Greg Dunn
Guest
Posts: n/a
 
      18th Dec 2003
> 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:(E-Mail Removed)...
> 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" <(E-Mail Removed)> 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
> >
> >
> >

>
>



 
Reply With Quote
 
Miha Markic
Guest
Posts: n/a
 
      18th Dec 2003
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" <(E-Mail Removed)> 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:(E-Mail Removed)...
> > 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" <(E-Mail Removed)> 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
> > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
CJ Taylor
Guest
Posts: n/a
 
      18th Dec 2003
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" <(E-Mail Removed)> 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
>
>
>



 
Reply With Quote
 
Greg Dunn
Guest
Posts: n/a
 
      18th Dec 2003
Ah...very easy. Many thanks!

--
Greg Dunn


"Miha Markic" <miha at rthand com> wrote in message
news:%(E-Mail Removed)...
> 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" <(E-Mail Removed)> 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:(E-Mail Removed)...
> > > 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" <(E-Mail Removed)> 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
> > > >
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding to Hierarchical Data Source (FAQs) Kent Boogaart Microsoft ASP .NET 5 2nd Feb 2006 05:55 PM
Binding a ComboBox in a Windows Form to a Hierarchical DataSet Greg Dunn Microsoft Dot NET Framework Forms 5 18th Dec 2003 09:18 PM
Binding a ComboBox in a Windows Form to a Hierarchical DataSet Greg Dunn Microsoft VB .NET 5 18th Dec 2003 09:18 PM
Binding a ComboBox in a Windows Form to a Hierarchical DataSet Greg Dunn Microsoft C# .NET 5 18th Dec 2003 09:18 PM
Binding hierarchical data neverstill Microsoft ASP .NET 3 9th Dec 2003 09:16 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:39 PM.