New Posts New Posts RSS Feed: Binding Combo Boxes
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Binding Combo Boxes

 Post Reply Post Reply
Author
Bill Jensen View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 31-Jul-2007
Location: United States
Posts: 229
Post Options Post Options   Quote Bill Jensen Quote  Post ReplyReply Direct Link To This Post Topic: Binding Combo Boxes
    Posted: 02-Oct-2007 at 3:45pm
In earlier correspondence, Dan asked:
 
How do I bind a ComboBox list to a constant list of values?
 
Bill J. Replied:
 
If you're using a DevEx ComboBoxEdit control, just leave the ListConverter data source blank.  In the designer view in the control's properties, select the "Edit Items" link at the bottom and type in the constant strings you want to appear in the list.
 
In the Dot Net Combo Box, there is an Items property with a collection editor to do the same thing.
 
I think this will work as long as the combo is bound to a string-valued property.
 
Dan replied:
 
I tried that but it came back blank.
 
What I did was add a string array in my presenter and then bound the combobox to that. Works like a charm.
 
The only problem I have is that I get the red exclamation next to it and it doesn't bind properly.
 
Value that is suppose to bind is the same as the values in the combobox.
Back to Top
Bill Jensen View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 31-Jul-2007
Location: United States
Posts: 229
Post Options Post Options   Quote Bill Jensen Quote  Post ReplyReply Direct Link To This Post Posted: 02-Oct-2007 at 3:58pm

I've tried this myself:

I added a string-valued property named "Direction" (and a PropertyDescriptor) to my Employee class.
 
Using the ControlBindingManager I bound the Direction property to a (DotNet) ComboBox, leaving the ListConverter configuration at default values.
 
I added a constant named "Direction" to ListConverterNames (in the Interface project)
 
In the ListConverterService (in the Foundation module) I added a new case for "Direction" that calls MakeDirectionConverter() to CreateServiceItemCore().
 
I added the method:
 

/// <summary>Get the global ListConverter for all TitlesOfCourtesy.</summary>

private static ListConverter MakeDirectionConverter()

{

ListConverter converter =

new ListConverter(typeof(string), Editability.Optional);

converter.ListSource = new BindingSource(mDirections, null);

converter.DisplayMember = "__Self";

return converter;

}

private static string[] mDirections = new string[] { "North", "South", "East", "West" };

to the ListConverterService.

Finally (!) I added this code to the presenter for my view:

/// <summary>Bind to the Direction List Control</summary>

/// <remarks>

/// Adds the proper ListConverter for Direction.

/// </remarks>

private void BindDirection() {

SetBindingListConverter(Employee.Descriptors.Direction, ListConverterNames.Direction);

}

This works--the list appears properly and the selected value is bound to the Direction property of the Employee entity.
 
Whew!  Thats quite a bit of stuff, though most of the complexity has to do with getting the ListConverter from a service, CAB style.  I'll ask Ward if he can recommend a simpler mechanism.
 
Bill
Back to Top
Linguinut View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Jun-2007
Location: United States
Posts: 394
Post Options Post Options   Quote Linguinut Quote  Post ReplyReply Direct Link To This Post Posted: 02-Oct-2007 at 4:03pm
I'd highly suggest utilizing the ListConverterService.  You could create your string list in the GetMyListBindingSource method (returns a BindableList).  The strings could technically come from anywhere...database, xml file, text file, etc.  Or, just hard code them.  Then, if you need that list elsewhere...it's all ready to go.
Back to Top
Bill Jensen View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 31-Jul-2007
Location: United States
Posts: 229
Post Options Post Options   Quote Bill Jensen Quote  Post ReplyReply Direct Link To This Post Posted: 10-Oct-2007 at 11:49am
Finally got a chance to run this by Ward.  This is in fact the best (and most Cabanaesque) solution.  So I stand by it.
 
And I agree with Bill C.--the ListConverterService is the way to go.
 
Bill J.
Back to Top
orcities View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Aug-2007
Location: United States
Posts: 454
Post Options Post Options   Quote orcities Quote  Post ReplyReply Direct Link To This Post Posted: 10-Oct-2007 at 1:40pm
Thanx Bill that did it. I wonder what I am doing wrong with my other list boxes.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down