Hello,
I'm relatively new to wxWindows, and experienced in C++. I'm trying to build a simple data entry program. The basic idea is that the window (a wxDialog, newProgramDlg ) will have a series of wxCheckBox's and wxTextCtrl's. I want each CheckBox to be associated with a single TextCtrl, so that we only try and read the data if the check box is true (thus the user can choose which fields to input). I plan on having numFIELDS = 5 say, (TextCtrl,CheckBox) pairs.
My initial code:
void newProgramDlg::CreateGUIControls(int numFields )
{
this->SetTitle(wxString("new Program Dialog"));
this->Center();
this->SetIcon(wxNullIcon);
wxFlexGridSizer *dialogSizer = new wxFlexGridSizer(2, 1, 10, 10);
for( int i = 0; i < numFields; i++ ){
wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
button_sizer->Add(new wxCheckBox(this, pow( 2, i ),myNames[i] ), 0, wxALL );
button_sizer->Add(new wxTextCtrl(this, pow(2,i+numFields)), 0, wxALL);
dialogSizer->Add( button_sizer, 0, wxALIGN_CENTER );
}
SetSizer(dialogSizer);
SetAutoLayout(TRUE);
dialogSizer->Fit(this );
dialogSizer->SetSizeHints( this );
}
Question 1: I'm currently using a binary coding (2^i or 2^(i+numFields)) to associate each CheckBox with a TextCtrl so that I can access them later through newProgramDlg::FindWindow. Is there an easier or more straightforward way to do this.
Question 2: Eventually I want to add some buttons. If the user clicks on OK, I want to validate each field (make sure it is a number in the proper range, I already built the validator). If all fields are valid, I want to return the values for those fields to the parent window and close the window. Otherwise, I want to keep the window on the screen and highlight the invalid fields.
How do I return these values to the parent window? Do I need to add a reference to an array in the newProgramDlg constructor?
Question 3: How will the parent window know when it's child closes? Is there some type of event it should catch?
Sorry if these questions are really basic, like I said, I'm just getting started. Thanks in advance for any help.
|