ComboBox Binding to a ReadOnlyList

ComboBox Binding to a ReadOnlyList

Old forum URL: forums.lhotka.net/forums/t/316.aspx


pfeds posted on Thursday, June 08, 2006

I'm not entirely sure how to do this, so would appreciate some advice.  This might be simple to do (or maybe not)?

I have an Employee Detail View that has a Location property - the site that they work at.  This property is naturally bound to the Employee object.  I now have a LocationList of LocationInfo objects.

What I want is to convert the Location text box to a combo box, with the data bound to the Location collection and the SelectedValue remaining bound to the Employee object.  Additionally this needs to default to the default site within the Location collection.

The reason I am posting is to see whether this is a feasible solution. In most CSLA projects it seems that selection/picker dialogs are used instead...?

 

pfeds replied on Thursday, June 08, 2006

Sorry, that was an end of the day post. I've just figured out how to do that Coffee [C]

I feel like a newbie developer now...

pfeds replied on Friday, June 09, 2006

Hmm, I do have a problem with this...

It seems that the databinding for the list in the combobox will alter the Employees Location property, therefore making the object dirty.

I've tried binding the list before and after the Employee object but suffer the same in both instances.  Has anyone done this successfully, and if so then how?

Any advice appreciated! Thanks.

xal replied on Friday, June 09, 2006

How are you filling your combobox? How are you setting up databinding? Paste some code! :)
I've never had issues like that...

Also, what is the default value for your object? Is it a valid value? what does it automatically change to? Does it change to -1?

If the combobox recieves an invalid value it'll default to something else (usually -1).
Perhaps you want to fill your combobox with an an extra "<Please select something>" that has a the same value as your object's default....


Andrés

pfeds replied on Friday, June 09, 2006

Hi xal,

The code is roughly as follows (in the Load event of the control):

{

   locationListBindingSource.DataSource = _locationList;

   cboLocation.DataBindings.Add(new Binding("SelectedValue", _employee, "Location");

}

 

The combo is bound via the locationListBindingSource, with both DisplayMember and ValueMember set to "LocationName" within the collection, and this list is currently populated with two locations:

Location1

Location2

 

The problem is as such, if the Employee's location is Location1 then everything works fine.  However, if it is Site2 then something occurs to make the Employee object dirty. Somehow the combination of the two bindings seems to cause this.

Any ideas?

pfeds replied on Monday, June 12, 2006

Anybody Stick out tongue [:P]

xal replied on Monday, June 12, 2006

Sorry, I saw your post the other day and forgot to reply... Embarrassed [:$]

You say "However, if it is Site2 then something occurs to make the Employee object dirty"
Site2 isn't in the list, so I suppose binding to selected value will fail and will reset the combobox to an empty value or something that exists on the list. What value is being set in your bo when databinding triggers the change?

Andrés

Copyright (c) Marimer LLC