Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
900
How to DataBind a multiselect UltraComboEditor to an Enum
posted
I have an integer field in the database, that can store the values of an enumeration.
The enum has the [Flags] attribute, that means its values are bitmasked and can be combined.
How can I show up the field in a Grid resp. in a multiselect Combobox?
 
A singleselect enum is no problem, I can use the ValueList property of the column resp. of the editor.
To allow multiselect, I could use the CheckedListSettings of the UltraComboEditor.
But how to set/get the values via DataBinding?
 
Taking the enum E:
[FlagsAttribute]
public enum E { One=1, Two=2, Four=4, Eight=8 }
 
If the field has the value 3, than the items One and Two should be selected in the DropDownList.
If I select the item Four too, than I have to save the value 7 to the field.
Which property of the UltraComboEditor should I DataBind to the field?
Parents
  • 48586
    Verified Answer
    posted

    Hello,

     

     Conversation which you want to do is a little complicate because when UltraComboEditor is managed to MultiSelect, it returns as value List<object>. However what I could suggest you is to is first to generate two methods. Fist one could convert single int to Enum flag:

     

    List<object> ConvertIntToE(int i, UltraComboEditor combo)

            {

                E es = (E)i;

                Notify("Value");

                return Enum.GetValues(typeof(E)).Cast<E>().Where(v => es.HasFlag(v)).Cast<object>().ToList<object>();

            }

     

    The second method should convert UltraComboEditor value to single int:

     

    int ConvertComboVlaueToInt()

            {

                List<object> l = (List<object>)ultraComboEditor1.Value;

                if (l == null)

                    return 0;

                int res = 0;

                foreach (object o in l)

                    res += (int)o;

                Notify("Value");

                return res;

            }

     

    So I have implement my idea in a user control , and have used UltraContinerEditor for editor of UltraGrid. Please see attached sample. More information about UltraContinerEditor you could find on the following link:

     

    http://help.infragistics.com/Help/NetAdvantage/WinForms/2012.1/CLR2.0/html/WinControlContainerEditor_Understanding_WinControlContainerEditor.html

    http://help.infragistics.com/Help/NetAdvantage/WinForms/2012.1/CLR2.0/html/WinControlContainerEditor_Using_WinControlContainerEditor.html

     

    I hope that this will helps you.

    97824.zip
Reply Children