General discussion

Locked

Handling ComboBox control in MFC

By psmanohar ·
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

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Handling ComboBox control in MFC

by donq In reply to Handling ComboBox control ...

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)

Collapse -

Handling ComboBox control in MFC

by psmanohar In reply to Handling ComboBox control ...

The question was auto-closed by TechRepublic

Collapse -

Handling ComboBox control in MFC

by Ktirf In reply to Handling ComboBox control ...

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<CString, unsigned long> 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!

Collapse -

Handling ComboBox control in MFC

by psmanohar In reply to Handling ComboBox control ...

The question was auto-closed by TechRepublic

Collapse -

Handling ComboBox control in MFC

by psmanohar In reply to Handling ComboBox control ...

This question was auto closed due to inactivity

Back to Web Development Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums