Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have an entity object "Account" that contain fields such that
C#
public class Account
{
    public string Name{get;set;}
    public int Type{get;set;}
}

Account Type is a fixed values such that {"basic","derived","no type",...}
I bind Name field to text box,I want to bind Type to combo box where string values appear as combo box items.
I bind Dictionary to ComboBox such that
C#
Dictionary<string, int> AccountType = new Dictionary<string, int>
	{
	  {"no type", 0},
	  {"basic", 1},
	  {"derived", 2}
	};
combo.DataSource = new BindingSource(AccountType, null);
combo.DisplayMember = "Key";
combo.ValueMember = "Value";

How can I bind to ComboBox where drop down list contain only unique values of strings that represent Int value.
Posted
Updated 8-Nov-14 0:30am
v2

1 solution

Swap the dictionary format. Or I misunderstood the question?

XML
Dictionary<int, string> AccountType = new Dictionary<int, string>
    {
      {0, "no type"},
      {1, "basic"},
      {2, "derived"}
    };
combo.DataSource = new BindingSource(AccountType, null);
combo.DisplayMember = "Key";
combo.ValueMember = "Value";
 
Share this answer
 
Comments
ibrahim_ragab 8-Nov-14 6:58am    
Thank you for your help,I want to implement choice list such that in LightSwitch.

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