Dialog advice needed

Fulvio Senore mailing at fsoft.it
Tue May 1 10:54:11 PDT 2007


Hello to everybody,

I am building my first wxWidgets application and I am very satisfied of 
the framework.
Until now I have been slowly learning how to do things by my myself, but 
this time I really need help from more experienced people.

My application needs to show a dialog with a tree control that may 
contain a lot of items. The user chooses an item and presses OK to 
proceed. The user is likely to show the dialog many times, always 
choosing the same item, or a near one.
The dialog has to be modal, since the user must choose an item before 
going on.

The problem is that if I use the standard code to show the modal dialog, 
the dialog is created each time so it "forgets" the previous selection, 
and the user has to navigate among many items each time.

I would like to create a hidden dialog at startup, to show it in a modal 
way when the user chooses a menu, and to hide it when the user presses 
the OK button. In this way the user will always find the dialog as he 
left it the previous time.

I tried this code.

At application startup I create the dialog:

m_ChooseVirtualFolderDialog = new CDialogChooseVirtualFolder(this, 
ID_DIALOG_CHOOSE_VIRTUAL_FOLDER, _("Choose virtual folder"));

When the user chooses a menu I show the modal dialog:

if( m_ChooseVirtualFolderDialog->ShowModal() != wxID_OK ) return;
long virtualFolderId = m_ChooseVirtualFolderDialog->GetVirtualFolderID();


In the dialog class I add a handler for clicking the OK button:

void CDialogChooseVirtualFolder::OnOKClick( wxCommandEvent& event )
{
    event.Skip(false);    // to suppress a warning
    if( m_VirtualFolderID > 0 )
        SetReturnCode( wxID_OK );
    else
        SetReturnCode( wxID_CANCEL );
    this->Show(false);
}

If everything is OK the code should return wxID_OK to the caller.
The code hides the dialog that is not destroyed until program termination.


ShowModal() should return wxID_OK if the user chooses an item and clicks OK.
This code works with Windows, but it does now work with Linux. In my 
Ubuntu 6.06 copy ShowModal() always returns wxID_CANCEL. I am using 
wxWidgets 2.8.3.



Does anybody know how to solve this problem, and may he show me how to 
do it?

Thanks in advance.

Fulvio Senore








More information about the wx-users mailing list