Solved

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

Posted on 2000-02-16
5
213 Views
Last Modified: 2013-11-20
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?
0
Comment
Question by:fredmastro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 4

Expert Comment

by:captainkirk
ID: 2529251
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...

0
 
LVL 2

Expert Comment

by:waseemanis
ID: 2529767
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.
0
 
LVL 2

Author Comment

by:fredmastro
ID: 2531149
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?
0
 
LVL 3

Accepted Solution

by:
SamHobbs earned 100 total points
ID: 2531616
Using the MFC document/view architecture the way it was designed to be used, you could read the data into your document, then put data into the view.

I agree with waseemanis that reading the entire file in is probably the best solution. More specifically, read the entire file into a collection in your document. The collection could be a CMap or it could be a CList or CArray. You could look at the COLLECT MFC sample for some examples that might help. For just the document processing, look at the colledoc.h and colledoc.cpp files.

Also my article at http://www.codeguru.com/bitmap/SimpleBMPViewer.shtml could help, but just the document processing portions. Instead of reading a bitmap, you would read your file. So instead of the LoadImage, you would have a loop to read the file. The advantage of overriding the OnOpenDocument is that you are still using MFC's logic for the file open dialog and such. In the document header, you would replace the m_Bitmap with a collection for your data. Other details I hope are obvious, such as you would not need the m_Bitmap.Attach.

For the view, probably captainkirk has explained that solution rather well. The COLLECT MFC sample might help here too.


0
 
LVL 3

Expert Comment

by:SamHobbs
ID: 2531646
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.
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question