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...
===============================
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;
}