ralph78
asked on
combobox
Hi!
i currently use a combobox control, and some code is executed on the "onchange" event. well, now i want to dynamicly change the selection of the combo. so i call the SetCurSel method, but the "onchange" event isn't sent anymore. (i tyed combo->PostMessage(CBN_SEL CHANGE), it doesn't work (i think the message is pending).
regards, Ralph
i currently use a combobox control, and some code is executed on the "onchange" event. well, now i want to dynamicly change the selection of the combo. so i call the SetCurSel method, but the "onchange" event isn't sent anymore. (i tyed combo->PostMessage(CBN_SEL
regards, Ralph
Call the onchange yourself after calling the SecCurSel.
Don't post the message.
Add a function to the CBN_SELCHANGE message in ClassWizard.
Then call it from the other function you use to SetCurSel();
I made a CFormView app for this test.
// Here is the message map showing the trapping of the CBN_SELCHANGE message
// The app also has a button that I use to set the current
// selection to offset #2.
BEGIN_MESSAGE_MAP(CMy20288 603View, CFormView)
//{{AFX_MSG_MAP(CMy2028860 3View)
ON_CBN_SELCHANGE(IDC_COMBO _CHANGE_ME , OnSelchangeComboChangeMe)
ON_BN_CLICKED(IDC_BUTTON_C HANGE, OnButtonChange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
////////////////////////// ////////// ////////// ////////// ////////// ////////// /
// CMy20288603View message handlers
void CMy20288603View::OnSelchan geComboCha ngeMe()
{
// TODO: Add your control notification handler code here
AfxMessageBox("Changed");
}
void CMy20288603View::OnButtonC hange()
{
m_cboChangeMe.SetCurSel(2) ;
OnSelchangeComboChangeMe() ;
}
Add a function to the CBN_SELCHANGE message in ClassWizard.
Then call it from the other function you use to SetCurSel();
I made a CFormView app for this test.
// Here is the message map showing the trapping of the CBN_SELCHANGE message
// The app also has a button that I use to set the current
// selection to offset #2.
BEGIN_MESSAGE_MAP(CMy20288
//{{AFX_MSG_MAP(CMy2028860
ON_CBN_SELCHANGE(IDC_COMBO
ON_BN_CLICKED(IDC_BUTTON_C
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//////////////////////////
// CMy20288603View message handlers
void CMy20288603View::OnSelchan
{
// TODO: Add your control notification handler code here
AfxMessageBox("Changed");
}
void CMy20288603View::OnButtonC
{
m_cboChangeMe.SetCurSel(2)
OnSelchangeComboChangeMe()
}
ASKER
well... there is a little problem:
i can't use this method because i only get a CWnd* (so i cast it to CComboBox* when i'm sure it's a combobox, but i can't call a function defined in one particular dialog)...
any idea?
i can't use this method because i only get a CWnd* (so i cast it to CComboBox* when i'm sure it's a combobox, but i can't call a function defined in one particular dialog)...
any idea?
The function is defined in whatever holds the control (View or Dialog).
If you're using a modeless dialog, I believe you can still call public functions defined in it.
What is the action that you want to trigger the change?
If you're using a modeless dialog, I believe you can still call public functions defined in it.
What is the action that you want to trigger the change?
ASKER
well, actually, i'm working with the viavoice sdk. so when i got a vocal event (a user message is sent to the dialog), i would like to change the value of a combo box. however, i can't use directly this combo. for instance, i can receive the vocal message "setcombo 1015 2" (i'm notified when this sentence is told). so i want the combobox which has the id 1015 change its selected item to its 2sd element.
((CComboBox *)curdlg->GetDlgItem(1015) )->SetCurS el(2);
//curdlg is the current dialog box
this way, i cant change the value of the selected item in my combobox, exactly as if i had clicked on it, but the "OnSelChange" function isn't called.
((CComboBox *)curdlg->GetDlgItem(1015)
//curdlg is the current dialog box
this way, i cant change the value of the selected item in my combobox, exactly as if i had clicked on it, but the "OnSelChange" function isn't called.
I sincerely don't believe you will be able to force that foreign dialog to recognize the change.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ralph, you may want to reject my proposed answer if it's not what you're looking for.
If you do, your question will get more exposure and a maybe a better answer.
If you do, your question will get more exposure and a maybe a better answer.