Solved

Combo Box Contents

Posted on 1998-08-17
7
244 Views
Last Modified: 2013-11-20
I want the combo box data in the dropdown list to come from a database.. In the sense if I increased the database contents the dropdown box should show the added items.. How do you do this..
A sample code will be very helpful..

thanks

0
Comment
Question by:guranimo
  • 6
7 Comments
 
LVL 8

Accepted Solution

by:
Answers2000 earned 20 total points
ID: 1320931
Bind a CComboBox variable to the combo box using the class wizard (say m_combo)

To fill the combo do

m_combo.ResetContents() ;
CString strItem ;
while ( _GetRecord(strItem) )
{
    m_combo.AddString( strItem ) ;
}

You'll have to change _GetRecord to the appropriate function based on what database access technology you're using.  Call this function in WM_INITDIALOG (OnInitDialog) or after the user adds to the database.

If you mean - how do I do it such that whenever somebody else (multi user) updates the database, the combo auto updates, you'd have to
(i) Either create a timer message, periodically query the database, cache the last set of results, compare the new results.  If they don't match, refill the combo
or
(ii) When the combo gains the focus update it (you could be clever and put in a dummy item saying "*Please make a selection*" or something

0
 

Author Comment

by:guranimo
ID: 1320932
The ResetContent() and AddString (), while compiling are given as error and that they are not members of CSting..
0
 

Author Comment

by:guranimo
ID: 1320933
The ResetContent() and AddString (), while compiling are given as error and that they are not members of CSting..
0
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

Author Comment

by:guranimo
ID: 1320934
The ResetContent() and AddString (), while compiling are given as error and that they are not members of CSting..
0
 

Author Comment

by:guranimo
ID: 1320935
The ResetContent() and AddString (), while compiling are given as error and that they are not members of CSting..
0
 

Author Comment

by:guranimo
ID: 1320936
The ResetContent() and AddString (), while compiling are given as error and that they are not members of CSting..
0
 

Author Comment

by:guranimo
ID: 1320937
I have it initialized to CComboBox type variable but when I excecute the program it crashes at the line
m_combo.AddString(stringitem);
which leads to an assertion failure in line 751 of afxwin2.inl file where the addstring is described..
please help


thanx
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Turn a spreadsheet into a vba executable. 2 86
mapBully challenge 6 134
how to split multiple lines delimiter : 8 99
Excel file not created as expected 7 72
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

773 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