how to know which notebook page we are in and which option is selected from the wxComboBox Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
disin
In need of some credit
In need of some credit
Posts: 9
Joined: Sat Apr 06, 2019 4:46 am

how to know which notebook page we are in and which option is selected from the wxComboBox

Post by disin »

Code: Select all

void MyFrame::OnChoice5(wxCommandEvent &Event)
{
wxCombo **combo =(wxCombo**)malloc(sizeof(wxCombo*)*5);
wxFrame *MainFrame=new wxFrame (ParentPanel,wxID_ANY,wxT("Frame"),wxDefaultPosition,wxSize(1200,500));
wxPanel *MainPanel=new wxPanel(MainFrame,wxID_ANY);
wxPanel **Panels=(wxPanels**)malloc(sizeof(wxPanels*)*5);
wxNoteBook *NoteBook=new wxNoteBook(MainPanel,-1,wxPoint(-1,-1),wxSize(-1,-1),wxNB_LEFT);
		for(int i=0;o<5;i++)
		{
		Panels[i]=new wxPanel(NoteBook,wxID_ANY,wxDefaultPosition,wxSize(1100,600));
		wxArrayStrings Strings;
		Strings.Add(wxT("One"));
		Strings.Add(wxT("Two"));
		Strings.Add(wxT("Three"));
		combo[i]=new wxComboBox(Panels[i],wxNewId(),wxT("Option"),wxDefaultPosition,wxSize(500,30),Strings,wxCB_DROPDOWN);
		NoteBook->AddPage(Panels[i],wxString::Format("Sheet %d",i+1));
		Connect(combo[i]->GetId(),wxEVT_COMMAND_COMBOBOX_SELECTED,wxCommandEventHandler(MyFrame::OnCombBoxSelect));
		}
	NoteBook->Show(true);
	MainFrame->Show(true);
	Center();
}

void MyFrame::OnCombBoxSelect(wxCommandEvent &event)
{
}
the function Onchoice5(), creates a Frame having a wxNoteBook of five page such that each pages have a wxComboBox
with option ("one", "two", "three")
the
" Connect(combo->GetId(),wxEVT_COMMAND_COMBOBOX_SELECTED,wxCommandEventHandler(MyFrame::OnCombBoxSelect));"
calls the function OnCombBoxSelect(wxCommandEvent &event)
when the option "one" or "two" or "three" is selected

so in the OnComboBoxSelect() function
1. how do we know which option ("one", "two", "three") have been selected
2. and in which page we are in
3. and also how do we get the page name and store it in a wxString object
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: how to know which notebook page we are in and which option is selected from the wxComboBox

Post by doublemax »

In cases like this the first thing to do is to browse through the public methods of the classes in question. E.g. wxNoteBook only has a few methods and you quickly would have discovered:
wxNotebook::GetPageText
https://docs.wxwidgets.org/trunk/classw ... edc1116910
wxNotebook::GetSelection
https://docs.wxwidgets.org/trunk/classw ... e31ea0f15e

However, the pointer to the wxNoteBook should be a member variable of MyFrame, otherwise it gets messy to retrieve it.

Code: Select all

void MyFrame::OnCombBoxSelect(wxCommandEvent &event)
{
  // assuming wxNotebook *m_notebook; as member variable
  wxLogMessage("notebook page: %d", m_notebook->GetSelection() );

  // get object that generated the event and make sure it's a wxChoice
  wxChoice *choice = wxDynamicCast(event.GetEventObject(), wxChoice );
  if( choice ) {
    wxLogMessage("wxChoice selection: %d", choice->GetSelection() );
  }
}
BTW: You're not freeing the memory allocated for "combo".
Use the source, Luke!
disin
In need of some credit
In need of some credit
Posts: 9
Joined: Sat Apr 06, 2019 4:46 am

Re: how to know which notebook page we are in and which option is selected from the wxComboBox

Post by disin »

thanks a lot doublemax
Post Reply