[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

Combo Box Contents

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
guranimo
Asked:
guranimo
  • 6
1 Solution
 
Answers2000Commented:
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
 
guranimoAuthor Commented:
The ResetContent() and AddString (), while compiling are given as error and that they are not members of CSting..
0
 
guranimoAuthor Commented:
The ResetContent() and AddString (), while compiling are given as error and that they are not members of CSting..
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
guranimoAuthor Commented:
The ResetContent() and AddString (), while compiling are given as error and that they are not members of CSting..
0
 
guranimoAuthor Commented:
The ResetContent() and AddString (), while compiling are given as error and that they are not members of CSting..
0
 
guranimoAuthor Commented:
The ResetContent() and AddString (), while compiling are given as error and that they are not members of CSting..
0
 
guranimoAuthor Commented:
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now