Filling a combo box from outside its dialog
-
I have a droplist combobox in a modal dlg called from mainfrm in an SDI. The combobox must obtain its initial selection ( a CString ) from the selected text in a listcontrol in a dlgbar, also in mainfrm. How do I accomplish this?
-
I have a droplist combobox in a modal dlg called from mainfrm in an SDI. The combobox must obtain its initial selection ( a CString ) from the selected text in a listcontrol in a dlgbar, also in mainfrm. How do I accomplish this?
You should be able to get a pointer to the ComboBox (use .GetDlgItem(ID_OF_COMBO)). Then with that pointer you should be able to access the members and functions of the ComboBox (comboBox->...). Here's an example: CDialog dlgModal; //initialize the dialog you are about to show. CComboBox* pCBox = dlgModal.GetDlgItem(ID_OF_COMBO); //get pointer to the ComboBox. int nDx = pCBox->FindString(-1, "string to find"); //get index of the item you want selected //the -1 tells it to search from the beginning ...and whatever else you need to do. ... dlgModal.DoModal(); //display the dialog I've not done anything quite like what you are attempting, but you should be able to get a pointer to any control on the form and use that pointer to access its members and functions. I hope that helps. David.
-
I have a droplist combobox in a modal dlg called from mainfrm in an SDI. The combobox must obtain its initial selection ( a CString ) from the selected text in a listcontrol in a dlgbar, also in mainfrm. How do I accomplish this?
Hello, the codegurus around the world.;) The easiest way to satisfy your requirement is to put public member value like m_sCurSelectedString in CMyMainFrame.
CMyMainFrame is the parent window of the dialog, dialog bar with ListBox.
I guess that ListBox is the same child level of the dialog bar since ListBox is declared
at CMyMainFrame class?m_sCurSelectedString is always updated if the user updates the selection of ListBox.
So, when the dialog is opened, m_sCurSelectedString compares the string in ComboBox
in OnInitDialog().So, how do we access m_sCurSelectedString from Dialog Box?
- Pass the parent's CWnd of dialog constructor arguement. or
- Use CWnd::GetParent() or
- Use AfxGetMainWnd() and cast the pointer of CMyMainFrame.
And, how do we update m_sCurSelectedString of ListBox.
I think that we can use MessageMap of ListBox in CMyMainFrame.The other way is that we can pass CWnd of ListBox on Dialog Bar
to the consturctor arguemnt of CMyDialog.
At this case, we can direclty access the currnet selected item of ListBox.:cool:I think that there are several other ways to do this.:eek: Have a nice day! -Masaaki Onishi-
-
I have a droplist combobox in a modal dlg called from mainfrm in an SDI. The combobox must obtain its initial selection ( a CString ) from the selected text in a listcontrol in a dlgbar, also in mainfrm. How do I accomplish this?
In the app class header file, after the app class definition, add the folowing line:
extern CMyApp theApp;
Add these declarations to your app class:
private:
CMainFrame* m_pMainFrame;
public:
CMainFrame* GetMainFramePtr() { return m_pMainFrame);In the OnInitInstance function of your app class, do this AFTER the main window is created:
m_pMainFrame = pMainFrame;
In the CMainFrame class, put a function that accepts a CComboBox* like so:
int CMainFrame::FillComboBox(CComboBox* pCombo)
{
// fill the combo box
// and return the number of things you put in it
return pCombo->GetCount();
}From within the OnInitDialog() function in the dialog box class, call your function like so:
theApp.GetMainFrame()->FillComboBox(&m\_ctrlComboBox);
I'm assuming that your dialog box class already has #include "MyApp.h" in it. :)