Saturday, December 17, 2005

Multi column combo box in Visual Basic



In MS Access a combobox can have several columns. Typically two columns are used, one for the id (which is hidden), and one for a descriptive field (which is shown).

Example: Show the name of the employee, but hide his id.

Strangely enough, in MS Visual Basic a combo box can't have more than one column.

One workaround is to add the descriptive field and the id into one long string, padding the descriptive field so it is say 200 characters long, making the id out os sight, but easily available using a substr() function.

Another way is to create your own multi column combo box. Patrick van Olderen did so. I just downloaded his version 11 of the control from 2002. It comes with an example test program in .exe form and also as vb project so you can study how the control can be used with code.

To register the ocx was a swift operation. Windows + R followed by:

regsvr32 "E:\programming\visual basic\ocx\ComboBoxLB.ocx"

(By the way, E is my 40GB iPod that since yesterday has started to work for me as my data storage, slightly out competing my 1GB Usb stick that was full.)

As always, Google groups, helped me to find the ocx and learn how to register it. Now, of course, all tips and tricks have been pasted into my treepad file on Visual Basic.

2 comments:

Anonymous said...

nice work

Anonymous said...

سيدتي