# Listbox in Win32 GUI



## Psychohyena (Apr 7, 2010)

Hi peeps,

I'm putting together a Win32 app (API) and crazy me decided to do it in c++ coding (no visual editors). The problem I've run into is I'm filling a listbox with data from a database, the obvious result of this is that the index value of the items are going to be different from the Primary Key value in the database.

My question is: How can I link the Primary Key to the correct record in the Listbox and use that value rather than the index value?

So far I have managed to get most of the app worked out but this is creating a major stumbling block for having everything work smoothly.

Let me know if you need any more information.


----------



## Kreij (Apr 9, 2010)

You can bind the data to the ListBox. and then set the DisplayMember property to what you want displayed in the listbox, and set the ValueMember property to the PK in the database.


----------



## W1zzard (Apr 9, 2010)

use LB_SETITEMDATA


----------



## Psychohyena (Apr 13, 2010)

Thanks for the suggestions guys. While it didn't help me achieve what I wanted it did help me realise that at my current skill level the way I was doing the application was ambitious and above my current capabilities. Though it does give me something to aim for, for now I'll use a visual developing environment.


----------

