Binding different ComboBoxes to same Table

  • Thread starter =?ISO-8859-1?Q?D=E9j=E0-vu?=
  • Start date
?

=?ISO-8859-1?Q?D=E9j=E0-vu?=

Hi everybody,

I have a configuration with popups, that look something like this:

CREATE TABLE TrafficSign(
ID NUMBER,
LocationInfo TEXT,
Quality_Day NUMBER,
Quality_Night NUMBER
...
)

CREATE TABLE QualityValues(
ID NUMBER,
Desc TEXT
)

The idea is that both Quality_XXX columns reference a row in the
QualityValues table. (which I would assume as a typical "popup/combobox" scenario)
Now my form shows the data of exactly one TrafficSign.
It contains two ComboBoxes: one for the Quality_Day, one for the Quality_Night.
My DataSet contains both tables "TrafficSign" and "QualityValues", the latter only once.
The ComboBoxes are bound to the DataSet by the following sequence:

public void BindPopup(ComboBox box,
string popupTab, string popupIDCol, string popupDescCol,
string dataTab, string dataCol)
{
box.DropDownStyle = ComboBoxStyle.DropDownList;
box.DataSource = globalDataSet.Tables[popupTab];
box.DisplayMember = popupDescCol;
box.ValueMember = popupIDCol;
box.DataBindings.Add("SelectedValue", globalDataSet.Tables[dataTab], dataCol);
box.SelectedIndexChanged += new EventHandler(DataChangedHandler)
}


The function BindPopup is called twice with different parameters.

public void FormLoadHandler(...)
{
...
BindPopup(visDay, "VisibilityValues", "ID", "Desc", "TrafficSign", "Visibility_Day");
BindPopup(visNight, "VisibilityValues", "ID", "Desc", "TrafficSign", "Visibility_Night");
...
}

Now the Problem:
When I change the value of one of the ComboBoxes lets say "visDay" the other changes
to the same value (which is also reflected in the data row later.
What I want (of course) is that both values will change individually.

What I don't really want is to duplicate the QualityValues table in the DataSet.
Is there another way (i.e. install different instances of CurrencyManagers in the data binding)
to achieve the desired behaviour?
Any ideas are very much appreciated!

Tilman


PS:
The project uses .NET CF 2.0.
For debugging purposes I also have a .NET project that runs the same app on the desktop.
The behavior shows up in both cases.
 
B

Bart Mermuys

Hi,

"Déjà-vu" said:
Hi everybody,

I have a configuration with popups, that look something like this:

CREATE TABLE TrafficSign(
ID NUMBER,
LocationInfo TEXT,
Quality_Day NUMBER,
Quality_Night NUMBER
...
)

CREATE TABLE QualityValues(
ID NUMBER,
Desc TEXT
)

The idea is that both Quality_XXX columns reference a row in the
QualityValues table. (which I would assume as a typical "popup/combobox"
scenario)
Now my form shows the data of exactly one TrafficSign.
It contains two ComboBoxes: one for the Quality_Day, one for the
Quality_Night.
My DataSet contains both tables "TrafficSign" and "QualityValues", the
latter only once.
The ComboBoxes are bound to the DataSet by the following sequence:

public void BindPopup(ComboBox box,
string popupTab, string popupIDCol, string
popupDescCol,
string dataTab, string dataCol)
{
box.DropDownStyle = ComboBoxStyle.DropDownList;
box.DataSource = globalDataSet.Tables[popupTab];

Haven't used CF2.0, but according to the SDK doc you can use BindingSource
(NET2.0/CF2.0) or DataView :

box.DataSource = new BindingSource(globalDataSet, popupTab);

or

box.DataSource = new DataView(globalDataSet.Tables[popupTab]);


In both cases their DataSource is different (different instance) for each
ComboBox which makes them navigate independently. The BindingSource also
gets a DataView (internally) which you can access through the List property,
in additition the BindingSource acts as a frontend for the CurrencyManager.

HTH,
Greetings

box.DisplayMember = popupDescCol;
box.ValueMember = popupIDCol;
box.DataBindings.Add("SelectedValue", globalDataSet.Tables[dataTab],
dataCol);
box.SelectedIndexChanged += new EventHandler(DataChangedHandler)
}


The function BindPopup is called twice with different parameters.

public void FormLoadHandler(...)
{
...
BindPopup(visDay, "VisibilityValues", "ID", "Desc", "TrafficSign",
"Visibility_Day");
BindPopup(visNight, "VisibilityValues", "ID", "Desc", "TrafficSign",
"Visibility_Night");
...
}

Now the Problem:
When I change the value of one of the ComboBoxes lets say "visDay" the
other changes
to the same value (which is also reflected in the data row later.
What I want (of course) is that both values will change individually.

What I don't really want is to duplicate the QualityValues table in the
DataSet.
Is there another way (i.e. install different instances of CurrencyManagers
in the data binding)
to achieve the desired behaviour?
Any ideas are very much appreciated!

Tilman


PS:
The project uses .NET CF 2.0.
For debugging purposes I also have a .NET project that runs the same app
on the desktop.
The behavior shows up in both cases.
 
R

RobinS

Are you binding both combo boxes to the QualityValues table
to show the available values, and then one should be stored in
Quality_Day and one in Quality_Night in the [TrafficSign] table?

I'm doing this one one of my forms. The user can select a product type.
The dropdown list shows all the values from the ProductType table,
but when I save it, it saves it to the Product table.

Do accomplish this (double binding), I use two BindingSource components.

TypeListBindingSource -- for the table displaying the possible values
ProductBindingSource -- for the table where I'm going to
store the result. This binding source is used by the rest of my fields
as well.

I did my data binding in design mode; here is the code generated for the
data
bindings. This is in VB, but it should be almost identical in C#.

ProductTypeComboBox.DataBindings.Add(New _
System.Windows.Forms.Binding("SelectedValue", _
Me.ProductBindingSource, "ProductType", True))
ProductTypeComboBox.DataSource = Me.TypeListBindingSource
ProductTypeComboBox.DisplayMember = "TypeName"
ProductTypeComboBox.ValueMember = "TypeValue"

Hope this helps.
Robin S.
----------------------------------------------------
public void BindPopup(ComboBox box,
string popupTab, string popupIDCol, string
popupDescCol,
string dataTab, string dataCol)
{
box.DropDownStyle = ComboBoxStyle.DropDownList;
box.DataSource = globalDataSet.Tables[popupTab];
box.DisplayMember = popupDescCol;
box.ValueMember = popupIDCol;
***THIS LINE IS REDUNDANT. You have already bound the combobox with the
previous
***statements.
box.DataBindings.Add("SelectedValue",
globalDataSet.Tables[dataTab], dataCol);
box.SelectedIndexChanged += new EventHandler(DataChangedHandler)
}


"Déjà-vu" said:
Hi everybody,

I have a configuration with popups, that look something like this:

CREATE TABLE TrafficSign(
ID NUMBER,
LocationInfo TEXT,
Quality_Day NUMBER,
Quality_Night NUMBER
...
)

CREATE TABLE QualityValues(
ID NUMBER,
Desc TEXT
)

The idea is that both Quality_XXX columns reference a row in the
QualityValues table. (which I would assume as a typical
"popup/combobox" scenario)
Now my form shows the data of exactly one TrafficSign.
It contains two ComboBoxes: one for the Quality_Day, one for the
Quality_Night.
My DataSet contains both tables "TrafficSign" and "QualityValues", the
latter only once.
The ComboBoxes are bound to the DataSet by the following sequence:

public void BindPopup(ComboBox box,
string popupTab, string popupIDCol, string
popupDescCol,
string dataTab, string dataCol)
{
box.DropDownStyle = ComboBoxStyle.DropDownList;
box.DataSource = globalDataSet.Tables[popupTab];
box.DisplayMember = popupDescCol;
box.ValueMember = popupIDCol;
box.DataBindings.Add("SelectedValue",
globalDataSet.Tables[dataTab], dataCol);
box.SelectedIndexChanged += new EventHandler(DataChangedHandler)
}


The function BindPopup is called twice with different parameters.

public void FormLoadHandler(...)
{
...
BindPopup(visDay, "VisibilityValues", "ID", "Desc", "TrafficSign",
"Visibility_Day");
BindPopup(visNight, "VisibilityValues", "ID", "Desc",
"TrafficSign", "Visibility_Night");
...
}

Now the Problem:
When I change the value of one of the ComboBoxes lets say "visDay" the
other changes
to the same value (which is also reflected in the data row later.
What I want (of course) is that both values will change individually.

What I don't really want is to duplicate the QualityValues table in
the DataSet.
Is there another way (i.e. install different instances of
CurrencyManagers in the data binding)
to achieve the desired behaviour?
Any ideas are very much appreciated!

Tilman


PS:
The project uses .NET CF 2.0.
For debugging purposes I also have a .NET project that runs the same
app on the desktop.
The behavior shows up in both cases.
 
?

=?ISO-8859-1?Q?D=E9j=E0-vu?=

Thanks a lot, your answer was the solution and saved me a lot of try and
most of all "error"!

Greetings
Tilman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top