Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Master, can you help me how to get single data from multiple coloumn in combobox VB.Net?
I will explain it, first i already create multiple coloumn in combobox, im concat two fields from 1 table, just say it id_material and Desc_material, and when i choose i want what write in combobox.text is just id_material, because i need only get that id_material, please help me

What I have tried:

i already tried many ways, but still fail to get it
Posted
Updated 9-Sep-19 20:40pm

That we cannot help you with: if you have concatenated two fields to create a new value to insert in the combobox, we have no idea where the first ends and the second begins - it's just a string now, and unless there is a very specific character between the two values, they cannot be reliably "untangled".

A much better idea would be to use this: Flat-MultiColumn Combobox with Autocomplete[^] or to databind the data behind it all to a single columns ComboBox and and use the DisplayMember and ValueMember properties to select the Desc_material to display to the user, and the id_material to return as the selected value.
 
Share this answer
 
Quote:
i already create multiple coloumn in combobox, im concat two fields from 1 table

No, you don't. It's still single column combobox.

Quote:
i need only get that id_material

It's quite easy to achieve. You have to set:
DisplayMember Property[^] to that concatenated string
and
ValueMember Property[^] to that id_material.

VB.NET
ComboBox1.DataSource = dataSet1.Tables["Materials"];  
ComboBox1.DisplayMember = "CommonNameForMaterialIdAndDescription";  
ComboBox1.ValueMember = "id_material";  


That's all!


For further details, please see:
ComboBox Class (System.Windows.Forms) | Microsoft Docs[^]
How to: Bind a Windows Forms ComboBox or ListBox Control to Data | Microsoft Docs[^]
 
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