Search code examples
mysqlvb.netwinformsvisual-studio-2013bindingsource

Display text but update with code in a combobox


I am new to VB.NET and I am afraid I have been spoiled by the Powerbuilder datawindows.

In a MySQL table there are columns which contain codes where the details are in a joined table. For example table boats has a column material containing “A” (Aluminium). “G”(GRP) etc.

I have a form with a number of tabs including a tab “BoatsTab”. I don’t use a datagridview but drag the columns from the dataset to the form. There can be multiple rows. What I am trying to do is display the material as “Aluminum” and to change the value by selecting from a drop-down ComboBox. Naturally updating should use “G” and not “GRP”. I can place a ComboBox on the form and populate it with a class containing code and description and retrieve the code from the selected item but this only works for one row as there is only one cb.

Is this possible?


Solution

  • When using Windows Form ComboBoxes, you can display a value which is different than the actual "database" value.

    For this you have to use the DisplayMember and ValueMember properties of the ComboBox class.

    Cheers