Groups | Blog | Home
all groups > dotnet compact framework > january 2007 >

dotnet compact framework : Binding different ComboBoxes to same Table


RobinS
1/12/2007 11:10:47 AM
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.
----------------------------------------------------

[quoted text, click to view]
***THIS LINE IS REDUNDANT. You have already bound the combobox with the
previous
***statements.
[quoted text, click to view]


[quoted text, click to view]

d-e-j-a-v-u NO[at]SPAM web.de
1/12/2007 6:20:50 PM
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.

Bart Mermuys
1/12/2007 6:49:46 PM
Hi,

[quoted text, click to view]

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


[quoted text, click to view]

d-e-j-a-v-u NO[at]SPAM web.de
1/15/2007 10:05:52 AM
Thanks a lot, your answer was the solution and saved me a lot of try and
most of all "error"!

Greetings
Tilman

[quoted text, click to view]
AddThis Social Bookmark Button