Problem databinding multiple ComboBoxes to a TypedList

Posts   
 
    
AlanD
User
Posts: 26
Joined: 19-Sep-2006
# Posted on: 02-Nov-2006 12:32:12   

Hi, I'm having a problem databinding ComboBoxes to a TypedList. I fire up two WinForms of the same type, each looking at a different instantiation of the same Entity. One property of the entity is changed using a ComboBox on the WinForm that points back to a single TypedList. Note that the ComboBoxes on both forms points back to the SAME TypedList. When I select a different value on the ComboBox, the value in BOTH WinForms changes. I thought that Currency Management was per WinForm, but this doesn't seem to be the case; it looks like somehow the TypedList is doing the Currency Managing, or at least only allowing one Current item.

Or, is it due to the update modes I've selected on the last few lines of code (see below)? I have tried to get changes to propagate both ways as fast as possible as I had some trouble with changes to the Entity not reflecting up to the WinForm control. (Although to be fair this was with a TextBox, not a ComboBox).

comboBox.DataBindings.Clear(); comboBox.DisplayMember = displayMember; comboBox.ValueMember = valueMember; comboBox.DataBindings.Add(propertyName, obj, dataMember); // obj is the entity comboBox.DataSource = dataSource; // This is the TypedList // Set binding modes to propagate changes both ways ASAP comboBox.DataBindings[0].DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged; comboBox.DataBindings[0].ControlUpdateMode = ControlUpdateMode.OnPropertyChanged;

C# 2.0, VS2005 Self-servicing LLBLGen PRO designer: 1.0.2005.1.Final, July 6th 2006, SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll version: 1.0.20051.60719

Thanks in advance for any help,

Alan

AlanD
User
Posts: 26
Joined: 19-Sep-2006
# Posted on: 02-Nov-2006 12:43:34   

Update: Removing the two UpdateMode statements at the end doesn't solve the problem, so it's not them.confused

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 02-Nov-2006 15:19:50   

Note that the ComboBoxes on both forms points back to the SAME TypedList

Do you mean both comboboxes are linked to the same instance of a TypedList?

AlanD
User
Posts: 26
Joined: 19-Sep-2006
# Posted on: 02-Nov-2006 15:40:21   

Yes, I do. But not to select from, just to use as a list of values that can be selected from to go in the Entity property, if that makes sense!stuck_out_tongue_winking_eye

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 03-Nov-2006 11:42:38   

A typedlist is a datatable, and datatables when bound to a control, will return a DataView which actually binds to the control.

The thing is, if you don't bind a dataview to the control but the typedlist, it will return the DefaultView instance, which is the same in both situations.

To avoid this, create two new DataView instances for the typedlist (just pass in the typedlist to each constructor) and bind these dataviews to the comboboxes. It now should work properly.

Frans Bouma | Lead developer LLBLGen Pro
AlanD
User
Posts: 26
Joined: 19-Sep-2006
# Posted on: 03-Nov-2006 12:37:13   

Ah yes, that makes sense. Thanks for your help, Alan