Click here to Skip to main content
15,894,955 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using VB2010 and I want to use Code to add some Product Name and productID into Combobox.(not using Database)
I tried to but I can not add both. I can only add product name or ProductID.

Please everybody help me.

Thanks in advance
Posted

You should create a struct which can hold your product info like this:

C#
struct Product
       {
           public string Name;
           public int ProductID;
       }


Then you can create a list of your product like this

C#
List<Product> products = new List<Product>(){new Product () {Name="a", ProductID=1}, new Product(){Name="b", ProductID=2}};
           comboProducts.DataSource = products;
           comboProducts.DisplayMember = "Name";
           comboProducts.ValueMember = "ProductID";


Hope this helps
 
Share this answer
 
use like that

cmbFiles.DisplayMember = "ProductName";
cmbFiles.ValueMember = "productID";
cmbFiles.DataSource = lstProduct
 
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