This is a migrated thread and some comments may be shown as answers.

DisplayMember not set

1 Answer 198 Views
ComboBox and ListBox (obsolete as of Q2 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
DNV Cleaner Energy
Top achievements
Rank 1
DNV Cleaner Energy asked on 09 Feb 2010, 07:57 PM
Hello,
I have a Winforms RadCombo box for which I am attempting to set a class derived from CollectionBase as the DataSource. I find that the DisplayMember of the comboxbox is set to an empty string. The ValueMember retains the correct column setting.

Any help is really appreciated...

Here are the relevant pieces of code:

FixedBillingPackageList.cs
===============================
 public class FixedBillingPackageList : ReadOnlyCollectionBase
    {

        #region Data Structure
        [Serializable]
        public struct FixedBillingPackageListInfo
        {
            // This has private members, public properties because
            // ASP.NET can't data bind to public members of a structure
            private int _fixedBillingPackageID; //**PK
            private string _packageName;
            private decimal _rate;

            public int FixedBillingPackageID
            {
                get { return _fixedBillingPackageID; }
                set { _fixedBillingPackageID = value; }
            }

            public string PackageName
            {
                get { return _packageName; }
                set { _packageName = value; }
            }
            public decimal Rate
            {
                get { return _rate; }
                set { _rate = value; }
            }

            public string PackageNamePrice
            {
                get
                {
                    return String.Format("{0} ({1})", _packageName, _rate);
                }
            }
        }
        #endregion //Data Structure

       #region Data Access
        protected void Fetch(object criteria)
        {
            //retrieve data from database
            Criteria crit = (Criteria)criteria;
            Database database = DatabaseFactory.CreateDatabase("ConnectionString");
            DbCommand dbCommand = database.GetSqlStringCommand("SELECT FixedBillingPackage.FixedBillingPackageID AS FixedBillingPackageID, FixedBillingPackage.PackageName AS PackageName, FixedBillingPackage.Rate AS Rate FROM FixedBillingPackage ");
            dbCommand.CommandType = CommandType.Text;
            SafeDataReader dataReader = new SafeDataReader(database.ExecuteReader(dbCommand));
            try
            {
                // Insert Blank row at the top of the list if specified.
                if (crit.IncludeBlankRow)
                {
                    FixedBillingPackageListInfo info = new FixedBillingPackageListInfo();
                    info.FixedBillingPackageID = -1;
                    info.PackageName = String.Empty;
                    info.Rate = 0;
                    InnerList.Add(info);
                }

                while (dataReader.Read())
                {
                    FixedBillingPackageListInfo info = new FixedBillingPackageListInfo();
                    info.FixedBillingPackageID = dataReader.GetInt16(0);
                    info.PackageName = dataReader.GetString(1);
                    info.Rate = dataReader.GetDecimal(2);
                    InnerList.Add(info);
                }
            }
            finally
            {
                dataReader.Close();
                dataReader.Dispose();
            }
        }

        #endregion Data Access
    }

MainForm.cs
================
MainForm.cs
===============


public MainForm()
{
   InitializeComponent();
   INitializeData();
}

private void InitializeData()
{

            FixedBillingPackageList packageList = FixedBillingPackageList.GetFixedBillingPackageList(true);
            comboFixedBillingPackage.BindingContext = new BindingContext();
           
            this.comboFixedBillingPackage.DisplayMember = "PackageName";
            this.comboFixedBillingPackage.ValueMember = "FixedBillingPackageID";
            comboFixedBillingPackage.DataSource = packageList;
}

1 Answer, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 11 Feb 2010, 09:59 AM
Hello Veeramani Pulacode,

Thank you for writing. I am afraid that the code you provided will not work because the standard complex data binding mechanism supports only IList and IListSource interfaces. Your collection needs to implement one of those. If you try the same code with the standard Microsoft ComboBox control it will throw an exception. Basically you need IList in order to work with any list control be it a combobox, listbox, grid etc.

Please write again if you need further assistance.

Regards,
Victor
the Telerik team


Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
DNV Cleaner Energy
Top achievements
Rank 1
Answers by
Victor
Telerik team
Share this question
or