in
Forums
Blogs
Files
Devexpress.Com
Client Center
Support Center
DevExpress Channel

How do I bind the ComboBoxEdit.Properties.Items value to my datasource

Last post 12/14/2008 8:23 AM by erit zheng. 6 replies.
Page 1 of 1 (7 items)
Sort Posts:
Previous Next
  • 8/14/2007 11:39 AM

    How do I bind the ComboBoxEdit.Properties.Items value to my datasource

    Hi guys,

    I have a simple ComboBoxEdit control and I want to bind the dropdown items to a datasource.  All of the examples that I've seen have code like the following...

    comboBoxEdit1.DataBindings.Add("EditValue", _Controller.BindingSource, _Controller.BindingSource.DataMember);

    Binding to EditValue binds successfully but only binds the first record of the datasource to the text field of the combo box, it doesn't add the remaining items to the dropdown list.  I've seen several posts recommending to use LookUpEdit instead, this would be fine but all of the examples mention binding to this same EditValue property.

    Specifically what I need to do is to bind the control to the Items property under the Properties group, or ComboBoxEdit.Properties.Items.  I've tried lines of code like the following but I always receive an exception since the property can't be found...


    comboBoxEdit1.DataBindings.Add("Items", _Controller.BindingSource, _Controller.BindingSource.DataMember);
    comboBoxEdit1.DataBindings.Add("Properties.Items", _Controller.BindingSource, _Controller.BindingSource.DataMember);

    Does anyone have any idea how can I access this particular property?

    Thanks in advance.

    Jeremy
     

     

  • 8/14/2007 3:24 PM In reply to

    Re: How do I bind the ComboBoxEdit.Properties.Items value to my datasource

    Use a LookupEdit control instead. Set the DisplayMember, ValueMember and DataSource properties, and you're set. Additionally, you can specify what columns to display in the drop-down.


     

    http://www.logisticdynamics.com
  • 7/7/2008 6:05 AM In reply to

    Re: How do I bind the ComboBoxEdit.Properties.Items value to my datasource

     

    Hi,

     

    Is the LookUpEdit Control available in the trial version?

     

    I have added the LookUpEdit control to the VS 2005 toolbox, however it is greyed out, along with many other controls.

     

  • 7/7/2008 11:57 AM In reply to

    Re: How do I bind the ComboBoxEdit.Properties.Items value to my datasource

    Sure. All controls are available in the trial version.

    http://www.logisticdynamics.com
  • 12/11/2008 9:15 AM In reply to

    Re: How do I bind the ComboBoxEdit.Properties.Items value to my datasource

    In the LookUpEdit there's also the column headings displayed.  Can I hide them if I only need one column (so like a normal dropdown)? 

    Or should I just use the standard combobox from .net/vs in such case? 

  • 12/11/2008 10:07 AM In reply to

    Re: How do I bind the ComboBoxEdit.Properties.Items value to my datasource

     ok, never mind, I found the property to disable the headings

  • 12/14/2008 8:23 AM In reply to

    Re: How do I bind the ComboBoxEdit.Properties.Items value to my datasource

    public class ComboITem

    {

        private string sValue;

        private string sDisplaytext;

        ComboItem(string sv,string sd)

        {

            sValue=sv;

            sDisplaytext=sd;
        }

        public ovveride string ToString()

        {

            return sDisplaytext;

        }

        public string Value

        {

        get

            {

                return sValue;
        }

        }

       public staic bool u_SetItem(ComboBoxEdit combo,DataSet ds_source)

       {

             foreach(datarow dr in ds_source.tables[0].rows)

            {

                      comboBoxEdit1.Properties.Items.add(new ComboITem(dr["displaycol"].tostring(),dr["valuecol"].tostring());

            }

       }

       public static string u_GetItemvalue(ComboBoxEdit combo)

       {

              return ((ComboITem)combo.selectitem).Value;
       }

       public static bool u_SelectItem(ComboBoxEdit combo,string svalue)

     {

         int iIndex=0;

           foreach(object obj in  comboBoxEdit1.Properties.Items)

         {

               if(((ComboITem)obj).Value==svalue)

                         break;

               iIndex++;

         }

        if(iIndex>=comboBoxEdit1.Properties.Items.Count)

           ---throw new exception() ---not found

        else

               comboBoxEdit1.Selectitem(iIndex)

        return true;

     }
    }

    I write this class for ComboboxEdit ,if you want to add item,

    ComboITem.u_SetItem(comboBoxEdit1,ds_Binding)

    if u want to get value for selected item:

    string svalue=ComboITem.u_GetItemvalue(comboBoxEdit1);

    if u want to display another item :

    ComboITem.u_SelectItem(comboBoxEdit1,svalue);

    this code not test,maybe u need to adjust it , if u have some question, i copy my code in my program to you.

     

Page 1 of 1 (7 items)
Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED