Dialogs in 2.8 Topic is solved
Dialogs in 2.8
Alright so up to now I was using
wxDialog::OnCancel(); and wxDialog::OnOK(), now these are gone in 2.8 I looked through the samples and in place they use wxDialog::EndModal() this however this is not working for me it destroys my dialog without validation. It says in the documentation to use wxDialog::SetAffirmativeId(), I changed all my dialog OK and Cancel buttons to be using wxID_OK and wxID_CANCEL as well, is the wxDialogSetAffirmativeId() supposed to be used in the init dialog to make the dialog know that the particular id is the OK button? A code snippit of the new way to handle OnOK and OnCancel would be really helpful, anybody have any suggestions?
thanks.
wxDialog::OnCancel(); and wxDialog::OnOK(), now these are gone in 2.8 I looked through the samples and in place they use wxDialog::EndModal() this however this is not working for me it destroys my dialog without validation. It says in the documentation to use wxDialog::SetAffirmativeId(), I changed all my dialog OK and Cancel buttons to be using wxID_OK and wxID_CANCEL as well, is the wxDialogSetAffirmativeId() supposed to be used in the init dialog to make the dialog know that the particular id is the OK button? A code snippit of the new way to handle OnOK and OnCancel would be really helpful, anybody have any suggestions?
thanks.
-
- Earned a small fee
- Posts: 19
- Joined: Fri Sep 09, 2005 4:24 pm
- Location: Berlin, Germany
- Contact:
Hi there,
I'm currently migrating my projects to 2.8.0 and the following worked fine for me:
hope that helps,
-Micky
I'm currently migrating my projects to 2.8.0 and the following worked fine for me:
Code: Select all
void bgIDialog::onOk(wxCommandEvent& event){
DoSomeFinalStuffHere(...);
// old code:
// wxDialog::OnOK(event);
// new code:
if ( Validate() && TransferDataFromWindow() ){
if ( IsModal() )
EndModal(wxID_OK);
else{
SetReturnCode(wxID_OK);
this->Show(false);
}
}
}
-Micky
der.micky wrote:Hi there,
I'm currently migrating my projects to 2.8.0 and the following worked fine for me:
hope that helps,Code: Select all
void bgIDialog::onOk(wxCommandEvent& event){ DoSomeFinalStuffHere(...); // old code: // wxDialog::OnOK(event); // new code: if ( Validate() && TransferDataFromWindow() ){ if ( IsModal() ) EndModal(wxID_OK); else{ SetReturnCode(wxID_OK); this->Show(false); } } }
-Micky
hey Micky,
I used that code you sent, the call to Validate() && TransferDataFromWindow() is good and I get into the first if statement and EndModal() is called, my dialog goes away but still the message that its "OK" still doesn't seem to be routed. So things in my dialog that set values in my application are not set as they should be.

thanks,
Gavin
-
- Knows some wx things
- Posts: 26
- Joined: Tue Nov 14, 2006 1:51 pm
- Location: Duesseldorf, Germany
Since I started with wxWidgets only after 2.7, I can't say how it was before, however, when I connect an event handler to wxID_OK and call event.Skip() after doint my own stuff, I don't need to do anything to close the dialog myself. Maybe this helps...
Code: Select all
void MyDialog::OnOk( wxCommandEvent& event ) {
// some stuff here
if ( Validate() && TransferDataFromWindow() )
event.Skip();
}
S.Volkenandt wrote:Since I started with wxWidgets only after 2.7, I can't say how it was before, however, when I connect an event handler to wxID_OK and call event.Skip() after doint my own stuff, I don't need to do anything to close the dialog myself. Maybe this helps...
Code: Select all
void MyDialog::OnOk( wxCommandEvent& event ) { // some stuff here if ( Validate() && TransferDataFromWindow() ) event.Skip(); }
Thank you very much it solved my problem.

- tierra
- Site Admin
- Posts: 1343
- Joined: Sun Aug 29, 2004 7:14 pm
- Location: Salt Lake City, Utah, USA
- Contact:
You should be able to just call event.Skip() without needing the 'if' statement here. So long as you are using wxID_OK, the default event handler will do validation. If you aren't using wxID_OK, that's when you need to use SetAffirmativeId().S.Volkenandt wrote:Code: Select all
void MyDialog::OnOk( wxCommandEvent& event ) { // some stuff here if ( Validate() && TransferDataFromWindow() ) event.Skip(); }