CSLA .NET

From Rockford Lhotka's Expert C# 2008 and VB 2008 Business Objects books

Welcome to CSLA .NET Sign in | Join | Help
in Search

Binding Property To Multi-Select List Box

Last post 01-08-2009, 10:53 PM by lukky. 7 replies.
Sort Posts: Previous Next
  •  01-07-2009, 4:38 PM 29557

    Binding Property To Multi-Select List Box

    I'm binding one of my business objects to my UI. 

    I've done a single-selection drop down list before by binding to an Integer property on my object.....no problem.

    But now I've got a multi-select list box on the UI and I need to create a new property on the object to bind to.  What is the best way to create a property to handle this multiple selection?

     

     

  •  01-08-2009, 7:06 AM 29571 in reply to 29557

    Re: Binding Property To Multi-Select List Box

    Well, what's the use case?  Does the BO need to know what objects are selected?
  •  01-08-2009, 8:36 AM 29581 in reply to 29571

    Re: Binding Property To Multi-Select List Box

    Yes, the business object needs to know which options are selected and which options are not selected.  Right now there are just 3 options, but that number could increase in the future.

    I had 2 initial ideas, but I don't think they're a good solution:

    1.) Try to use a string property and somehow store/bind the selections as a comma separated string.  I'm pretty sure this will NOT work.

    2.) Create a property that contains a collection of "Option" objects.  The "Option" object would have 3 properties: Id (Integer), Description (String), Selected (Boolean).  I think I could get this to work but I have doubts about whether this is a good solution.

    Multi-select list boxes are a commonly used control.....so surely someone else has run into this.  Can anybody make some suggestions or give examples of how you've handled this? 

     

     

     

  •  01-08-2009, 11:35 AM 29594 in reply to 29581

    Re: Binding Property To Multi-Select List Box

    Option 2 would sound like your best bet.  I assume you're going to store the fact that one of the options is selected, correct?
  •  01-08-2009, 11:43 AM 29595 in reply to 29594

    • lukky is not online. Last active: 07-04-2009, 6:55 AM lukky
    • Top 50 Contributor
    • Joined on 05-29-2006
    • Sherbrooke, Qc, Canada
    • Posts 85
    • Points 1,415

    Re: Binding Property To Multi-Select List Box

    Just an idea, but would a "flagged enum" be thinkable ?

    Make the BO property of type YourEnum, and since it's a flagged enum, you can use a mask to check which one is active/inactive. Then it becomes a matter of making the UI control display those properly.

    If you need to map some more data to each enum, like a description etc, then a dictionnary<MyEnum, MyEnumInfo> could be used, where MyEnumInfo would hold all thge necessary data associated with each option.

    How does that sound ?

    Regards

     


    Luc Morin, T.P.
    http://www.stlm.ca
  •  01-08-2009, 2:47 PM 29606 in reply to 29581

    Re: Binding Property To Multi-Select List Box

    I implemented option 2 in one or two of my business classes and was quite happy with it
  •  01-08-2009, 3:55 PM 29608 in reply to 29606

    Re: Binding Property To Multi-Select List Box

    I have the Id (Integer) and Description (String) binding correctly. 

    But I'm struggling with the Selected (Boolean).

    How did you bind the boolean "Selected" property on your busines object to the "Selected" property on the ListItem?

     

  •  01-08-2009, 10:53 PM 29615 in reply to 29608

    • lukky is not online. Last active: 07-04-2009, 6:55 AM lukky
    • Top 50 Contributor
    • Joined on 05-29-2006
    • Sherbrooke, Qc, Canada
    • Posts 85
    • Points 1,415

    Re: Binding Property To Multi-Select List Box

    Attachment: MultiSelectEnum.zip
    Hi,

    I don't know if this would help the Original Poster, but please take a look at the attached sample C# project.

    It implements the idea I mentioned in my previous post in this thread.

    Hope this helps.



    Luc Morin, T.P.
    http://www.stlm.ca
View as RSS news feed in XML

Please contact Magenic for your .NET consulting
and CSLA .NET mentoring needs.
Please consider making a donation to help support the ongoing development of CSLA .NET.

Make donation through PayPal - it's fast, free and secure!
Why donate?
Powered by Community Server, by Telligent Systems