Clearing the edit box in ccombobox
-
I populate the combobox in OnInitDialog - which is only called upon dialog start and after a change to the database such as adding or deleting a record. I am trying to clear the dropdown style edit box (drop list style would be preferred due to the static edit box) from my DisplayRecord function (called at the end of OnInitDialog), and this is where I have instantiated m_wndComboBox, and from where I call m_wndComboBox.InsertString(0,"",0). The control exists on a modeless dialog, which is trying to open at the time of the assert.
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
lctrncs wrote:
...this is where I have instantiated m_wndComboBox...
m_wndComboBox
should be a member variable, not local to some function.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
What does my OnSelChangeCombo function look like? It is rather simple: 1. Pointer to the Combobox with assert if NULL, 2. code to return index of selected item in listbox from control directed alpha listing (thank you Chris Losinger!), 3. dirtyflag check of record and associated commit if true, 4. call of the GotoRecord function.
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
Ok, what I have here may help, or it may not since it is not entirely like what you have. I have a
CRecordset
-derived class that reads from the Employees table of the Northwind database. I have a dialog with a combobox (having theCBS_DROPDOWNLIST
style) and listbox. Selecting an item from the combobox will add it to the listbox. The selection in the combobox is then cleared.BOOL CMyDlg::OnInitDialog()
{
CDialog::OnInitDialog();CDatabase db; CSet rs(&db); rs.Open(); while (! rs.IsEOF()) { m\_combo.AddString(rs.m\_LastName); rs.MoveNext(); } rs.Close(); m\_combo.InsertString(0, ""); return TRUE; // return TRUE unless you set the focus to a control
}
void CMyDlg::OnSelchangeCombo1()
{
int nIndex = m_combo.GetCurSel();
CString strItem;
m_combo.GetLBText(nIndex, strItem);
m_list.AddString(strItem);m\_combo.SetCurSel(0);
}
Is this close?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
lctrncs wrote:
...this is where I have instantiated m_wndComboBox...
m_wndComboBox
should be a member variable, not local to some function.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
As I said, I have never tried to instantiate a class instance so that I can use the dot operator. I tried to instantiate it in a number of locations (mainframe.cpp main.c etc.) without success. So where should I instantiate my m_wndCombobox so that I can use the dot operator as you suggest m_combo.InsertStinrg(0,"") ? Why should the dot operator work when a pointer does not?
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
-
As I said, I have never tried to instantiate a class instance so that I can use the dot operator. I tried to instantiate it in a number of locations (mainframe.cpp main.c etc.) without success. So where should I instantiate my m_wndCombobox so that I can use the dot operator as you suggest m_combo.InsertStinrg(0,"") ? Why should the dot operator work when a pointer does not?
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
lctrncs wrote:
So where should I instantiate my m_wndCombobox so that I can use the dot operator as you suggest
It should belong to the class that owns it (hence the
m_
prefix). In my example,m_combo
andm_list
are both members ofCMyDialog
.lctrncs wrote:
Why should the dot operator work when a pointer does not?
Pointer variables use ->, while non-pointer variables use a dot. In reality,
pointer->member
is equivalent to:
(*pointer).member
See here for more on the member-selection operator.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
lctrncs wrote:
So where should I instantiate my m_wndCombobox so that I can use the dot operator as you suggest
It should belong to the class that owns it (hence the
m_
prefix). In my example,m_combo
andm_list
are both members ofCMyDialog
.lctrncs wrote:
Why should the dot operator work when a pointer does not?
Pointer variables use ->, while non-pointer variables use a dot. In reality,
pointer->member
is equivalent to:
(*pointer).member
See here for more on the member-selection operator.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
So I should right click on CDialog, choose Add Member Function and enter Ccombobox and m_combo to instantiate m_combo as a member CDialog?
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
-
So I should right click on CDialog, choose Add Member Function and enter Ccombobox and m_combo to instantiate m_combo as a member CDialog?
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
lctrncs wrote:
So I should right click on CDialog, choose Add Member Function and enter Ccombobox and m_combo to instantiate m_combo as a member CDialog?
No. Use ClassWizard (Ctrl+W) to associate a member variable with a control.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
Ok, what I have here may help, or it may not since it is not entirely like what you have. I have a
CRecordset
-derived class that reads from the Employees table of the Northwind database. I have a dialog with a combobox (having theCBS_DROPDOWNLIST
style) and listbox. Selecting an item from the combobox will add it to the listbox. The selection in the combobox is then cleared.BOOL CMyDlg::OnInitDialog()
{
CDialog::OnInitDialog();CDatabase db; CSet rs(&db); rs.Open(); while (! rs.IsEOF()) { m\_combo.AddString(rs.m\_LastName); rs.MoveNext(); } rs.Close(); m\_combo.InsertString(0, ""); return TRUE; // return TRUE unless you set the focus to a control
}
void CMyDlg::OnSelchangeCombo1()
{
int nIndex = m_combo.GetCurSel();
CString strItem;
m_combo.GetLBText(nIndex, strItem);
m_list.AddString(strItem);m\_combo.SetCurSel(0);
}
Is this close?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
Well I got things running like you show here - the Class Wizard info was key - but it still does not clear the edit box in either dropdown or drop list mode - any other suggestions?
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
-
Well I got things running like you show here - the Class Wizard info was key - but it still does not clear the edit box in either dropdown or drop list mode - any other suggestions?
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
If you can narrow this project down to just the relevant lines, you can e-mail it to me and I'll take a look.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
If you can narrow this project down to just the relevant lines, you can e-mail it to me and I'll take a look.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
Thank you. I spent some time with it this weekend and got it working. Thank You! Your assistance was of great service to me! Thank you again!
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
-
Thank you. I spent some time with it this weekend and got it working. Thank You! Your assistance was of great service to me! Thank you again!
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
Overall, what did you do to finally get it going?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb