SelectedIndexChanged event in comboA causes same event to fire in comboB

M

moondaddy

I have a vb.net 1.1 winforms app and have several combo boxes on a form 2
combos have the same data and are populated from the same data table using
the bind method. One is the ShipToAddress and the other is the
BillToAddress. when the user selects an address in the shipto combo, after
its SelectedIndexChanged event fires, the SelectedIndexChanged event fires
in the BillTo combo which, of course, is causing big problems.

Why is this? is it because they are bound to the same data table? Is it a
bug in vs 1.1? Can anyone recommend a fix or work around for this?

Thanks.
 
M

Mark Mischke

My first guess would be that it has something to do with both controls
sharing a common DataSource reference.

Try cloning the DataTable, so each ComboBox has equivalent, but
physically different, bound DataTables:

For instance, if your DataTable is called dt:

ComboA.DataSource = dt.Clone()
ComboB.DataSource = dt.Clone()

All of this is based upon the assumption (which may be incorrect) that
bound data container events may play a role in the triggerring of
certain control events. In general, it's usually safer to avoid
letting multiple objects share common references, unless you have a
specific reason to do so.

I hope this is useful...
 
M

moondaddy

Yes, this fixed the problem. actually just before I got your msg I tried
something similar such as creating a new dataset and merging the table into
it. I think cloning may be better. anyway, this worked, but I hope this
can get fixed in the future because if I need to update the dataset client
side and a bunch of controls are using the dataset as a datasource, then
every time the dataset gets updated, all the controls would have to be
rebound again which defeats some of the benefit of ado dataset and binding
them to controls where the data in the control stays in sync with the
dataset.

Thanks for the reply.
 
S

Stephany Young

I think that cloning datatables or creating new datatables is overkill.

This is what dataviw objects are designed for.

If you bind multiple controls to a databale then then when the current
pointer in the table moves then all the bound controls will reflect that
movement.

If you have a dataview for each control then the current pointer moves in
the dataview and not the datatable, thus making each control independent but
still getting it's list from the same physical data but via a different
logical path.
 
M

moondaddy

Thanks! That's really good to know. I thought I was saving steps by just
binding straight to the table, but I know better now.
 

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