Click here to Skip to main content
15,905,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i'm getting flowing exception while binding combo box in widows form application




"Cannot bind to the new display member."


Code

C#
 ArrayList arr1 = new ArrayList();
      Item objItem = new Item();
      objItem.Name="Vat";
      objItem.Id="2";
      arr1.Add(objItem);

      cmbLedgerType.DataSource = arr1;

      cmbLedgerType.DisplayMember = "Name";
      cmbLedgerType.ValueMember = "Id";
============================================================

Class Item
{
   public string Name;
   public string Id;
}
Posted
Updated 29-Jan-14 3:10am
v2

Check this link
 
Share this answer
 
Bind the Data at last only..

C#
cmbLedgerType.DisplayMember = "Name";
          cmbLedgerType.ValueMember = "Id";
          cmbLedgerType.DataSource = arr1;
 
Share this answer
 
Comments
Member 10296413 30-Jan-14 6:33am    
I chnged the code but in combo box i'm getting "WindowsFormsBilling.Item"
Karthik_Mahalingam 30-Jan-14 7:19am    
try this code..
ArrayList arr1 = new ArrayList();
Item objItem = new Item();
objItem.Name = "Vat";
objItem.Id = "2";
arr1.Add(objItem);

DataTable dt = new DataTable();
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Id", typeof(string));
arr1.OfType<item>().ToList().ForEach(k => dt.Rows.Add(k.Name, k.Id));
cmbLedgerType.DisplayMember = "Name";
cmbLedgerType.ValueMember = "Id";
cmbLedgerType.DataSource = dt;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900