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
440
Populate DropDownList from a Generic List<TObject>
posted

Can I bind a generic list objects to a UltraGridColumn.ValueList.DataSource? The object is a generic object contains fields mapped from database table. Here is my code snippet.

public class ListData

{

public string Code { get; set; }

public string Description { get; set; }

public string Others { get; set; }public ListData(string code, string descrition, string others)

{

Code = code;

Description = Description;

Others = others;

}

}

***** The app ***

List<ListData> listTest = new List<ListData>();

list.Add( new ListData("a", "Code A", "Other A") );

list.Add( new ListData("b", "Code B", "Other B") );

list.Add( new ListData("c", "Code C", "Other C") );

list.Add( new ListData("d", "Code D", "Other D") );

UltraGridColumn col = new UltraGridColumn();

col.Type = ColumnType.DropDownList;

col.ValueList.DataSource = list;

col.ValueList.DisplayMember =
"Description";

col.ValueList.ValueMember = "Code";

Of course, this does not work. That is reason why I am using Reflection to populate the ValueListItems now. However, I would love to bind the list objects directly to the dropdownlist column to gain the speed and cleaner code. Am I missing anyting during the column binding?