Link to home
Start Free TrialLog in
Avatar of fredmastro
fredmastroFlag for United States of America

asked on

Connecting a Combo and Edit box to a Text based or Access based Database

Here's what I have,

1) A dialog box with a NAME_COMBO box, and a SOURCE_EDIT box. Also I have an INSTALL_BUTTON.

2) A Text file, but I can deal with an Access file, I need it to have two 'tables' one called NAME and one called SOURCE. I perfer a text file but if I have to do an access .mdb file let me know. In the file the name is a frienly name and the source is the path to execute a .exe file. Ex.
NAME            SOURCE
-----------------------
Program 1       \\Folder\\Install.exe

Soooo, how do I get the COMBO drop down box in the dialog frame to pull up the names in the file, and then when it's selected, automaticly pull the source info for that name and put it in the Edit box in the dialog. That way I can use the Install button the run the .exe in the SOURCE_EDIT box using //.. system(varible) ..//

Did I explain that ok?
Avatar of captainkirk
captainkirk

1) you would either use a CFile object (with or without a CArchive object) or just straight fread() calls to get the data into memory - perhaps a class with name and source data members will do.

2) parse the name and source out of the input

3) use the AddString() method of your combo box in a loop to place names into it from the list read in. Use the SetItemData() method to put the pointer for the corresponding class object which contains your name / source pair in the item data for the entry.

4) create an OnSelChange handler for the combo where you can retrieve the item data for the selected entry in the combo box and from that, retrieve the source and place it in the edit box with SetWindowText().

hope that helps...

If you have to pares the strings all right then you might as well keep the entire mapping ie. the NAME <-> SOURCE in a CMap object. That ways you won't have to worry about the File operations.

But all this would also depend on your situation and requirements.

Luck,
Waseem.
Avatar of fredmastro

ASKER

Well my problem is, I need some code to help me out, I don't know how to set that up. Would all this fall under the function where the button is pressed? OnClick? And what would I type in?
ASKER CERTIFIED SOLUTION
Avatar of SamHobbs
SamHobbs

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ooops, I am sorry. Probably overriding OnOpenDocument is not worthwhile. I forgot that the reason I overrode OnOpenDocument is because the LoadImage does the open and close. So it is probably better to use the override of Serialize that the AppWizard generates. You could probably use CArchive::ReadString to read your records and then parse each record into your document.