Solved

combobox

Posted on 2002-04-13
8
885 Views
Last Modified: 2013-11-20
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_SELCHANGE), it doesn't work (i think the message is pending).

regards, Ralph
0
Comment
Question by:ralph78
  • 5
  • 2
8 Comments
 
LVL 6

Expert Comment

by:Triskelion
ID: 6939127
Call the onchange yourself after calling the SecCurSel.
0
 
LVL 6

Expert Comment

by:Triskelion
ID: 6939142
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(CMy20288603View, CFormView)
     //{{AFX_MSG_MAP(CMy20288603View)
     ON_CBN_SELCHANGE(IDC_COMBO_CHANGE_ME, OnSelchangeComboChangeMe)
     ON_BN_CLICKED(IDC_BUTTON_CHANGE, OnButtonChange)
     //}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CMy20288603View message handlers

void CMy20288603View::OnSelchangeComboChangeMe()
{
     // TODO: Add your control notification handler code here
     AfxMessageBox("Changed");
}

void CMy20288603View::OnButtonChange()
{
     m_cboChangeMe.SetCurSel(2);
     OnSelchangeComboChangeMe();
}
0
 

Author Comment

by:ralph78
ID: 6941301
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?
0
 
LVL 6

Expert Comment

by:Triskelion
ID: 6941772
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?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:ralph78
ID: 6942038
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))->SetCurSel(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.
0
 
LVL 6

Expert Comment

by:Triskelion
ID: 6943266
I sincerely don't believe you will be able to force that foreign dialog to recognize the change.
0
 
LVL 4

Accepted Solution

by:
AmitAgarwal earned 50 total points
ID: 6961923
Hi ralph78
try out this
i have created a dialogbased application.


void CTempDlg::OnButton1()
{
     CComboBox* pCombo = (CComboBox*)GetDlgItem(IDC_COMBO1);
     pCombo->SetCurSel(2);


     WPARAM wParam;
     LPARAM lParam;
     wParam = MAKEWPARAM(IDC_COMBO1,CBN_SELCHANGE);
     lParam = (LPARAM)pCombo->m_hWnd;
     ::SendMessage(this->m_hWnd,WM_COMMAND,wParam,lParam);
     
     
}

void CTempDlg::OnSelchangeCombo1()
{
     AfxMessageBox("Sel Change");    
}

hope this will help you
0
 
LVL 6

Expert Comment

by:Triskelion
ID: 6962902
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.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sumNumber challenge 16 98
twoTwo  challenge 35 86
sumHeights2  challenge 7 76
Annoying "thing" blocks my view 4 50
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

708 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now