controls are interacting even though they have different binding contexts

G

Guest

I have a windows form containing a listbox and a datagrid. Eac
control's DataSource is a different DataView from the same DataTable
Each control has its own binding context. The pseudo-code I use to se
up the controls is as follows

listBox.DataSource = view1
listBox.DisplayMember = "Field1"
listBox.BindingContext = new BindingContext()

dataGrid.DataSource = view2
dataGrid.BindingContext = new BindingContext()

If I make changes to any of the cells of the top 2 rows of th
datagrid, I get a SelectedIndexChanged event raised for the listBox

This is driving me crazy for the past 2 days. Is there anyway to kee
that event from happening or to test that it is bogus??

Thanks for the help

Dav
 
J

Johan Jooris

Try this

bm = me.bindingcontext(datasource, datatable)
bm.suspendbinding
do your changes
bm.resumebinding
 
G

Guest

Thanks, but that didn't help. I tried SuspendBinding on both the ListBox and Datagrid's data sources

I am currently using the following kluge that does seem to work
savedIndex = listBox.SelectedIndex
do my changes to the datagrid..
listBox.SelectedIndex = savedIndex

This sure looks like a !@#$%^&* kluge to me. Can anyone explain what is going on and/or give me a more palatable workaround

Thanks..

Dav

----- Johan Jooris wrote: ----

Try thi

bm = me.bindingcontext(datasource, datatable
bm.suspendbindin
do your change
bm.resumebindin
 
G

Guest

Dave - Have you tried setting the new binding contexts before you set the datasource and display member fields?
 
Top