PC Review


Reply
Thread Tools Rate Thread

Datarelation between two comboboxes?

 
 
Tore Bostrup
Guest
Posts: n/a
 
      31st Jan 2005
I have searched high and low for documentation I can understand or sample
code for setting up a datarelation between two ComboBoxes. But so far, all
I have found is either not helpful (for instance - "don't post a reply, I
have found out how to do it" but without saying how - which was asked) or
indicates that since the ComboBox doesn't have a DataMember property it
won't work.

I have defined the datarelation and my code runs, but I get all the rows
shown in the "child" combobox.

Can anybody please direct me to a sample or tell me what I am missing
(sorry - my code is on an offline system at the moment but it doesn't work
correctly either...)?

TIA,
Tore.


 
Reply With Quote
 
 
 
 
Hemang Shah
Guest
Posts: n/a
 
      31st Jan 2005
Hello Tore

Can you explain better what exactly are you trying to accomplish with the
two comboboxes ?

Is it that when you select a value in combobox1, you want relevant
information to show in combobox2 ?

If so, you have to make sure the dataSource property of the two comboboxes
are the same, if they are, and you have setup the correct relation in your
dataset, you should be fine.

For some reason if you cannot have the datasource of both these combo boxes
to be the same, you need to use the CurrencyManager Class to work that.

Hope that helps.

HS
"Tore Bostrup" <newspost_at_bostrup.us> wrote in message
news:%(E-Mail Removed)...
>I have searched high and low for documentation I can understand or sample
> code for setting up a datarelation between two ComboBoxes. But so far,
> all
> I have found is either not helpful (for instance - "don't post a reply, I
> have found out how to do it" but without saying how - which was asked) or
> indicates that since the ComboBox doesn't have a DataMember property it
> won't work.
>
> I have defined the datarelation and my code runs, but I get all the rows
> shown in the "child" combobox.
>
> Can anybody please direct me to a sample or tell me what I am missing
> (sorry - my code is on an offline system at the moment but it doesn't work
> correctly either...)?
>
> TIA,
> Tore.
>
>
>



 
Reply With Quote
 
Tore Bostrup
Guest
Posts: n/a
 
      31st Jan 2005
I want to implement a master/child relationship. When the user selects one
of the values in the first combo, I want to populate the second combo with
the choices related to the first.

Tore.

"Hemang Shah" <(E-Mail Removed)> wrote in message
news:VfSdnQADAbYMs2PcRVn-(E-Mail Removed)...
> Hello Tore
>
> Can you explain better what exactly are you trying to accomplish with the
> two comboboxes ?
>
> Is it that when you select a value in combobox1, you want relevant
> information to show in combobox2 ?
>
> If so, you have to make sure the dataSource property of the two comboboxes
> are the same, if they are, and you have setup the correct relation in your
> dataset, you should be fine.
>
> For some reason if you cannot have the datasource of both these combo

boxes
> to be the same, you need to use the CurrencyManager Class to work that.
>
> Hope that helps.
>
> HS
> "Tore Bostrup" <newspost_at_bostrup.us> wrote in message
> news:%(E-Mail Removed)...
> >I have searched high and low for documentation I can understand or sample
> > code for setting up a datarelation between two ComboBoxes. But so far,
> > all
> > I have found is either not helpful (for instance - "don't post a reply,

I
> > have found out how to do it" but without saying how - which was asked)

or
> > indicates that since the ComboBox doesn't have a DataMember property it
> > won't work.
> >
> > I have defined the datarelation and my code runs, but I get all the rows
> > shown in the "child" combobox.
> >
> > Can anybody please direct me to a sample or tell me what I am missing
> > (sorry - my code is on an offline system at the moment but it doesn't

work
> > correctly either...)?
> >
> > TIA,
> > Tore.
> >
> >
> >

>
>



 
Reply With Quote
 
NuTcAsE
Guest
Posts: n/a
 
      31st Jan 2005
The way i do it is i create a data view for the child table and bind
the view to the combobox. Then handle the SelectedIndexChanged event of
the first combobox and add the following code:

if (comboBox1.SelectedValue is int) {
int val = (int) comboBox1.SelectedValue;
DataView view = (DataView) comboBox2.DataSource
view.RowFilter = "Id = " + val.ToString();
}

comboBox1 is the master selection combobox, where as comboBox2 is the
child combobox. Maybye this method might help you out.

 
Reply With Quote
 
Hemang Shah
Guest
Posts: n/a
 
      31st Jan 2005
The ideal way is to add both these tables in a dataset, set the relationship
between them.

Make the datasource of the child combobox point to the name of the relation
you created and you will have it all working, without writting a single line
of code!

Let me know if you need help.

HS
"Tore Bostrup" <newspost_at_bostrup.us> wrote in message
news:%(E-Mail Removed)...
>I have searched high and low for documentation I can understand or sample
> code for setting up a datarelation between two ComboBoxes. But so far,
> all
> I have found is either not helpful (for instance - "don't post a reply, I
> have found out how to do it" but without saying how - which was asked) or
> indicates that since the ComboBox doesn't have a DataMember property it
> won't work.
>
> I have defined the datarelation and my code runs, but I get all the rows
> shown in the "child" combobox.
>
> Can anybody please direct me to a sample or tell me what I am missing
> (sorry - my code is on an offline system at the moment but it doesn't work
> correctly either...)?
>
> TIA,
> Tore.
>
>
>



 
Reply With Quote
 
Tore Bostrup
Guest
Posts: n/a
 
      1st Feb 2005
I *do* need help. I'm using code generated datasets, and I'm using the
DisplayMember and ValueMember of the combo boxes. I've set the relation
between them (as best I could figure), but the two boxes just don't
synchronize. All my searching seems to wind up at the CurrencyManager
object, but neither documentation nor examples I've seen help me understand
what I need to do.

Free from memory (I've tried several things, but in essence, my code has
revolved around the following pseudocode statements):

Create and fill "masterTable" in myDataSet
Create and fill "childTable" in myDataSet (with all values)

Create array of DataColumns for masterDS and childDS to use in definint the
relation
Define the relation "relationName" (uses two columns for the relationship,
thus the two arrays)

cboMaster.DataSource = myDataSet.Tables("masterTable")
cboMaster.DisplayMember = "DisplayColumnName"
cboMaster.ValueMember = "ValueColumnName"

cboChild.DataSource = myDataSet.Relations("relationName").ChildTable()
cboChild.DisplayMember = "ChildDisplayColumnName"
cboChild.ValueMember = "ChildValueColumnName"

This is apparently not sufficient to make the two comboboxes synchronized,
but for the life of me I can't figure out what is missing (or wrong).

I've tried several variations on the above, including specifying only the
datatable name instead of the Relations() specification for the child
datasource (the datatables are actually results sets generated by stored
procedures, and not physical database tables), using (or attempting - in
some cases giving errors "couldn't bind to...") different forms of more
fully qualified members ("childTable.Child...ColumnName"), etc.

Sure I can do this with other approaches (I have) - the DataReader doesn't
appear to give me a way to bind a ValueMember - but I tried that last
night/this morning after extensive sleep deprivation, so I don't really
know...

BUT - this is a perfect application for using the DataRelation, so I really
want to learn how to do that (in code).

TIA,
Tore.



"Hemang Shah" <(E-Mail Removed)> wrote in message
news:fIKdnVbb3cnG52PcRVn-(E-Mail Removed)...
> The ideal way is to add both these tables in a dataset, set the

relationship
> between them.
>
> Make the datasource of the child combobox point to the name of the

relation
> you created and you will have it all working, without writting a single

line
> of code!
>
> Let me know if you need help.
>
> HS
> "Tore Bostrup" <newspost_at_bostrup.us> wrote in message
> news:%(E-Mail Removed)...
> >I have searched high and low for documentation I can understand or sample
> > code for setting up a datarelation between two ComboBoxes. But so far,
> > all
> > I have found is either not helpful (for instance - "don't post a reply,

I
> > have found out how to do it" but without saying how - which was asked)

or
> > indicates that since the ComboBox doesn't have a DataMember property it
> > won't work.
> >
> > I have defined the datarelation and my code runs, but I get all the rows
> > shown in the "child" combobox.
> >
> > Can anybody please direct me to a sample or tell me what I am missing
> > (sorry - my code is on an offline system at the moment but it doesn't

work
> > correctly either...)?
> >
> > TIA,
> > Tore.
> >
> >
> >

>
>



 
Reply With Quote
 
Tore Bostrup
Guest
Posts: n/a
 
      1st Feb 2005
Yes, I do something similar, but this particular app seems to be a really
good match for use of the DataRelation, and I want to learn how to make it
work.

Thanks anyway,
Tore.

"NuTcAsE" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> The way i do it is i create a data view for the child table and bind
> the view to the combobox. Then handle the SelectedIndexChanged event of
> the first combobox and add the following code:
>
> if (comboBox1.SelectedValue is int) {
> int val = (int) comboBox1.SelectedValue;
> DataView view = (DataView) comboBox2.DataSource
> view.RowFilter = "Id = " + val.ToString();
> }
>
> comboBox1 is the master selection combobox, where as comboBox2 is the
> child combobox. Maybye this method might help you out.
>



 
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
DataRelation Tony Johansson Microsoft C# .NET 1 22nd Aug 2008 02:37 PM
DataRelation Tony Johansson Microsoft C# .NET 2 18th Aug 2008 03:47 PM
Master Detail Comboboxes (DataRelation on dataSources) Greg Microsoft Dot NET Framework Forms 0 19th Jan 2004 03:23 PM
DataRelation between two comboboxes Stefan Microsoft Dot NET Framework Forms 0 27th Nov 2003 03:42 PM
DataRelation between two comboboxes Stefan Microsoft C# .NET 0 27th Nov 2003 03:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:52 AM.