Click here to Skip to main content
15,797,062 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a combo box with list of data.
i want to display the distinct value of data in ComboBox and with value member.

Below is my code:

List<templateentity> objTemp = null;
objTemp = (List<templateentity>)note.Body;
cmbDataset.DataSource = objTemp;
cmbDataset.DisplayMember = "DatasetName";
cmbDataset.ValueMember = "DatasetID";

You can do this, (you may have to tweak it a bit to complie and work for you)
ddlName.DataSource = items.Select(item=>item.Name).Distinct().ToList();

ddlSize.DataSource = items.Select(item=>item.Size).Distinct().ToList();

ddlPrice.DataSource = items.Select(item=>item.Price).Distinct().ToList();

And then find the itemID based on the selection of all three dropdown lists.

This is C# and assumes that you have LINQ

Hope this helps.

Edit-- (if no LINQ)
IList<string> names = new List<string>();

foreach (Item item in Items)
    if (!names.Contains(item.Name))

ddlName.DataSource = names;

//Do similar for price and size.

Edit (use SQL commands)
select distinct Name from Item
select distinct Size from Item
select distinct Price from Item
Share this answer
var filterData = objTemp.Select(x => new { DatasetID = x.DatasetID, DatasetName = x.DatasetName }).Distinct();
cmbdataset.DataSource = filterData.ToList()
Share this answer

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