CCombBox reinitialization problem
Michael S. Raymond -- nontech@iag.net Tuesday, March 25, 1997 Environment: VC4.0, Win95 Ok, I am writing an small, CPropertySheet/Page based application for entering medical expenses into an Access database. There is nothing really amazing/difficult about the application - except for two minor but troubling points. 1) The CPropertySheet is operating in a modal state - but I have suppressed the OK, Cancel, Apply, and Help buttons and replaced them with Save, Clear, and Done. I have carefully set the tab order so a user can key in data on the page and press Enter to save it. Everything (including the focus) seems to work fine. However, if the user clicks on one of my buttons, the button visually depresses - but when the user presses Enter with a button selected, the button activity takes place but the button does not depress. NOTE: I have overridden the default IDOK() to prevent the modal CPropertySheet from closing. In this function, I tried a variety of CButton and CWnd functions for setting control/window state - but nothing had any effect on the button(s). The buttons are all members of the CPropertySheet class and they are created dynamically on the page. I am sure it is a messaging thing - but I am unable to locate an example that helps clear up my problem. 2) The 'Clear' button (described above) sends a message to the CPropertyPage-derived class for the currently selected page. The message instructs the page to clear all selections/values from the fields. While all of my other (CEdit) fields clear just fine, two CComboBox controls do not clear. I have tried using CComboBox::Clear(), CComboBox::Reset(), SelectString() [after setting up a blank entry in the box], and even CWnd.SetWindowText with no luck. The following code is an excerpt from the CPropertyPage-related function for clearing the fields: LRESULT CExpensePage::OnClear(WPARAM wParam, LPARAM lParam) { // expense page m_CategoryCombo.Clear(); m_PatientNameCombo.Clear(); m_Concluded = FALSE; m_TransactionAmount = 0; m_PaymentAmount = 0; m_TransDate = '\0'; UpdateData(FALSE); // don't know if this is necessary return lParam; } Seems like the Clear() function should do the trick. Any suggestions? Thanks in advance for your help Michael S. Raymond nontech@iag.net
tiger@flynet.de Friday, March 28, 1997 [Mini-digest: 3 responses] You should call Clear() after UpdateData(FALSE). If you call UpdateData after you've called Clear() and there's a CString Member associated to your ComboBox, UpdateData will put the string back into the edit-section of your ComboBox. Hope this helps. /////////////////////////////////////// // // // Frank Leuenberger // // tiger@flynet.de // // // /////////////////////////////////////// -----From: "Greg Tighe"> 2) The 'Clear' button (described above) sends a message to the > CPropertyPage-derived class for the currently selected page. The > message instructs the page to clear all selections/values from the > fields. While all of my other (CEdit) fields clear just fine, two > CComboBox controls do not clear. I have tried using CComboBox::Clear(), > CComboBox::Reset(), SelectString() [after setting up a blank entry in > the box], and even CWnd.SetWindowText with no luck. The following code > is an excerpt from the CPropertyPage-related function for clearing the > fields: > > Seems like the Clear() function should do the trick. Any suggestions? > CComboBox::Clear() clears (deletes) any currently selected text *within the edit control* of a combobox. It's like selecting some text in a text editing control and then hitting the 'Delete' key. If all the text in the edit control attached to your combobox was selected when you invoked CComboBox::Clear() then the text would disappear. Seems like what you want to call is CComboBox::SetCurSel (-1). According to the online doco: CComboBox::SetCurSel int SetCurSel( int nSelect ); /***********************************************/ Return Value The zero-based index of the item selected if the message is successful. The return value is CB_ERR if nSelect is greater than the number of items in the list or if nSelect is set to =961, which clears the selection. Parameters nSelect=A0=A0=A0Specifies the zero-based index of the string to select. If =961, any current selection in the list box is removed and the edit control is cleared. /*********************************************/ -Greg Tighe Applied Intelligent Systems, Inc. Ann Arbor, MI gdt@aisinc.com -----From: "Dalmer Junior" ---------- > From: Michael S. Raymond > To: mfc-l@netcom.com > Subject: CCombBox reinitialization problem > Date: Tuesday, March 25, 1997 11:46 PM > > Environment: VC4.0, Win95 > > 2) The 'Clear' button (described above) sends a message to the > CPropertyPage-derived class for the currently selected page. The > message instructs the page to clear all selections/values from the > fields. While all of my other (CEdit) fields clear just fine, two > CComboBox controls do not clear. I have tried using CComboBox::Clear(), > CComboBox::Reset(), SelectString() [after setting up a blank entry in > the box], and even CWnd.SetWindowText with no luck. The following code > is an excerpt from the CPropertyPage-related function for clearing the > fields: > > LRESULT CExpensePage::OnClear(WPARAM wParam, LPARAM lParam) > { > // expense page > m_CategoryCombo.Clear(); > m_PatientNameCombo.Clear(); > m_Concluded = FALSE; > m_TransactionAmount = 0; > m_PaymentAmount = 0; > m_TransDate = '\0'; > UpdateData(FALSE); // don't know if this is necessary > > return lParam; > } > > Seems like the Clear() function should do the trick. Any suggestions? > you should use the member function SetCurSel( -1 ). The -1 says to the Combo that any current selection in the list box is to be removed and the edit control cleared. I hope help you (:P []s, -- ***************************************************************** * Dalmer B. A. Junior Light-Infocon * * mail: dalmer@light-infocon.com Software Engineer * * Office Tel: (954) 450-0085 * * FAX : (954) 438-1995 -------- __o * * http://www.light-infocon.com ------- _`\<,_ * * "Life is Short Ride Tough" ------- (*)/ (*) * *****************************************************************
Become an MFC-L member | Вернуться в корень Архива |