Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Comments
[no name] 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 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 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
Member 9496620 14-Aug-15 2:12am    
Hii a using a combobox as in the example in solution 2.
if i write the name i need to select the combobox does not return the 'selectedvalue' value but if i click on the name all works fine. how can i force the combobox to return the selectedvalue in this case ?
thank you.

1 solution

HI,

Its simple buddy

Let's say, you have a combo box "ComboCustomerGroup"

VB
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

VB
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!!
 
Share this answer
 
v3
Comments
soeun tony 8-Aug-12 0:21am    
Hi a4ashiq,
Your simple is very useful for me. Thank you so much for this posted.

TONY
a4ashiq 8-Aug-12 0:25am    
You're welcome dude. Rate the answer if it helped you..
Thank you
Volynsky Alex 8-Aug-12 19:13pm    
Thanks a4ashiq185!
jabbarpatel 15-Jan-13 7:19am    
nice example... thanks
J3ssy Pmntra 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900