Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hi all experts,
 
i have one combo box called "Customer Group". This combo box will get all customer group in database from table "CustomerGroup" and in this table it has 2 columns (Code and Name). i want to display "Name" columns in Combo box and when i save it get the "Code" Column to other table(Customer Table).
 
Does anybody know how to do that?
 
Thanks
 
TONY
Posted 7-Aug-12 16:40pm
Comments
Wes Aday at 7-Aug-12 23:04pm
   
Yes, I am quite sure that quite a few people know how to do this. Sounds pretty trivial. The question for you is, "What have you tried and what specific problem are you having?". Where is the code that you wrote that demonstrates the problem that you are experiencing? Do you not know how to create a project? Start Visual Studio? Connect to a database? Query a database? Except for, "Does anybody know how to do that?," you didn't even ask any sort or a question or describe any sort of a problem.
soeun tony at 8-Aug-12 0:12am
   
Hi Wes Aday,
i said about combo box.So it means that i already created a project. Have you ever dropped a combo box without created project?. We need to created Project First.Am i right? Here is my query to display customer group "select code,name from customergroup". My question is how can i get the group code when i select group name in combo box?
Thanks
TONY
Sergey Alexandrovich Kryukov at 8-Aug-12 0:51am
   
No, no. There are at least four different but similar types called "ComboBox". Why anyone would try to answer for all cases? Please, be more specific. To start with, exact type name, please.
--SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

HI,
 
Its simple buddy
 
Let's say, you have a combo box "ComboCustomerGroup"
 
dim CustGroupDT as DataTable=GetCustomerGroupNameAndCode()
 
Me.ComboCustomerGroup.DataSource=CustGroupDT
 
Me.ComboCustomerGroup.DisplayMember="Name"
 
Me.ComboCustomerGroup.ValueMember="Code"
 

and when you save the data to your table(Customer Table), use
 
CustomerGroupCode=Me.ComboCustomerGroup.SelectedValue
 
This will give you the "Code" corresponding to the "Name" of the selected item of your combobox
 
Hope it works for you
Have a nice code day!!
  Permalink  
v3
Comments
soeun tony at 8-Aug-12 0:21am
   
Hi a4ashiq,
Your simple is very useful for me. Thank you so much for this posted.
 
TONY
a4ashiq at 8-Aug-12 0:25am
   
You're welcome dude. Rate the answer if it helped you..
Thank you
Volynsky Alex at 8-Aug-12 19:13pm
   
Thanks a4ashiq185!
jabbarpatel at 15-Jan-13 7:19am
   
nice example... thanks
Jessy Pimentera at 12-Aug-14 10:43am
   
Is it possible to have more than one ValueMamber? Or theres another solution for that?

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



Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 17 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100