Discussion Locked

Handling ComboBox control in MFC

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi,

I'm developing a database application using MFC. In few areas, i'm using Combo box control. In that i'm populating the list of employees. Whenever a user selects an employees name from the combo box, i just need to fetch the concern employee id without writing a second SQL statement just by passing employees name in the where condition. Is there anyway to handle employees id and employees name in a combo box when i populating itself.

Kindly provide me an help or sample code which willbe helpful for my problem.

Thanks in advance.

Manohar

5 replies

by donq

I'm not familiar with MFC however in Access one would create a 2 column Combo box with the ID in column 1, and Name in column 2. Then the developer would link the column 1 value to the field you want to populate with the user ID.

I'm sure MFC must use something similar? (I hope - good luck)

by ktirf

Unfortunately, MFC does not have such a thing as the previous answerer tells. I'm afraid you'll have to maintain the whole list of pairs id-name yourself. It is not so difficult, but it may be quite expensive the number of such pairs is large.
In the class of a window containing that combo box you define the map:

std::map employees;

if you prefer CMap, use CMap, it doesn't matter. Then in the procedure attached to WM_CHANGE of that combo box, you retrieve an active string value and search the map for it. Of course, you have to fill the map during initialization with the results if the appropriate SELECT query.
Hope I have helped you. Cheers!

This discussion is closed to new replies.