Groups | Blog | Home
all groups > dotnet windows forms databinding > july 2007 >

dotnet windows forms databinding : Combobox parent child update problem



Raggy Mcfadden
7/7/2007 7:52:01 AM
Hello,


In a windows form I have 2 comboboxes. One depends on the values selected in
the other. In a one-to-many relation. This is done by setting the datasource
of the other to the relation between the two. It all works unless I change
the value of only the first combobox. Then the other combobox displays the
first on the list, but actually nothing is selected. When I hit "save" on the
datanavigator it doesn't save the right value - it just keeps the old value.

All the bindings are done in the designer, and all are correct, because if I
actually select a new value from the second combobox, everything works. Only
when the second combobox is left untouched by the user does the problem occur

This seems like a common problem, i.e. bug, but as yet, I haven't been able
to find a common solution.


RB
7/7/2007 10:00:47 PM
When the value is changed in the first, does the SelectedIndexChanged event
fire in the second?

If the second list is on the many side, it doesn't seem like you would want
it to arbitrarily select one of the many values. If you want the first one
in the list to be selected, set the selected index value of the second to be
0. You might need an application.doevents on your first combobox
selectedIndexChanged event before you tell the second box what value to
select.

If the relationship makes the change for you and only the display value is
changed, you can also force a change in the underlying record wtih something
like the following:

Dim Order As PR_DataDataSet.OrdersRow = _

CType(CType(OrdersBindingSource.Current, Data.DataRowView).Row, _

PR_DataDataSet.OrdersRow)

Order.MyValue = ComboBox2.SelectedValue

Your endedit and update events will store this.


RB

--
remove underscore to send me mail, no spam
[quoted text, click to view]

Raggy Mcfadden
7/8/2007 12:24:00 PM
Hey,


Thanks for the effort. However, it won't work.

See comments below...

[quoted text, click to view]
No - However, SelectedIndexChanged cannot be trusted because it is not
certain that the old value wasn't the first on the list.

[quoted text, click to view]
I only want it to store the value it shows. I cannot just store the first on
the list in case the user selects a different value. Also, the second list
might be empty, in that case I need to store NULL.

I'm thinking there is a simple step in this setup, I am missing.


RB
7/16/2007 9:50:22 PM
Raggy:

If you have an Ok button, you can read the values of the two combo boxes
once the user has made their selections. One other thought was to read the
sender and act on a choice in combo1, combot2 or your Ok button.
http://msdn2.microsoft.com/en-us/library/aa457091.aspx

RB

--
remove underscore to send me mail, no spam
[quoted text, click to view]

AddThis Social Bookmark Button