Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am creating combobox dynamically to which i am assigning a list of objects

C#
class Fields
{
public string key{ get; set; }
public string value{ get; set; }
}
List column = new List();
column = str.split(',').Tostring();
 
BindingList obj = new BindingList();
for (int k = 0;k<columnheader.count;k++)>
{
obj.Add(new Fields() { key= column[k].ToString(),
value= column[k].ToString() });
}
}
Combobox combobox = new Combobox(); 
combobox.Datasource = obj;


in the combobox.Items it is showing Fields

but i want in my combobox.Items as value of key
Any suggestions
Posted
Updated 5-Sep-12 20:17pm
v2
Comments
D-Kishore 6-Sep-12 2:16am    
why you are positng same question again, delete any of your question

1 solution

I've got many suggestions to your code, but the answer of your question is:

C#
class Fields
{
    public string key { get; set; }
    public string value { get; set; }
    public override string ToString()
    {
        return value;
    }
}


"but i want in my combobox.Items as value of key" Didn't understand if you wanted key or value to be displayed. I choosed value. ;)
 
Share this answer
 
v2
Comments
Shubham @R$ 25-Jul-14 6:48am    
I want Searchable Combo With Dropdown With Multiple Columns. .This Is Not Working Please Give Me Kind Help.Thanks In Advance

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