Click here to Skip to main content
14,298,693 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

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.

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[^]
   

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




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