whick radio box is checked? Topic is solved

If you are using wxDev-C++ for your wxWidgets design, please ask your questions here instead of in IDE Related.
Post Reply
Mavverick
Earned a small fee
Earned a small fee
Posts: 18
Joined: Tue Sep 09, 2008 12:14 pm
Location: Brasil

whick radio box is checked?

Post by Mavverick » Thu Oct 23, 2008 4:38 pm

Hi!

I have a radiobox with 2 options: 1 robot or 2 robots.
and i need to open a certain frame if option 1 is checked and open a different frame if option 2 is checked.
so what do i have to use to get that?
like...

Code: Select all

void RobotsDlg::btnOKClick(wxCommandEvent& event)
{
	if (rdbNumRobots[1].checked == true)
	{
           JuntasFrm TempJuntasFrm(this);
           TempJuntasFrm.Show();
        }
}
obviously it's not working with that ".checked"... so what should i use instead?
thanks

timg
Earned some good credits
Earned some good credits
Posts: 148
Joined: Mon Jan 23, 2006 6:52 pm

Post by timg » Thu Oct 23, 2008 6:28 pm

If you are using a wxRadioBox, why would you not use GetSelection()?

Mavverick
Earned a small fee
Earned a small fee
Posts: 18
Joined: Tue Sep 09, 2008 12:14 pm
Location: Brasil

Post by Mavverick » Fri Oct 24, 2008 11:57 am

yea.. i tried this:

Code: Select all

/*
 * btnOKClick
 */
void RobotsDlg::btnOKClick(wxCommandEvent& event)
{
      // insert your code here
      int GetSelection();
      if (rdbNumRobots->GetSelection() == 0)
      {
          JuntasFrm TempJuntasFrm(this);
          TempJuntasFrm.Show();
      }
)
and it's compiling.. but when i press the button OK, it's not opening my Juntas frame..
do u have any idea why? is it something wrong in my code?

Mavverick
Earned a small fee
Earned a small fee
Posts: 18
Joined: Tue Sep 09, 2008 12:14 pm
Location: Brasil

Post by Mavverick » Fri Oct 24, 2008 1:43 pm

ah yea.. i think i can't use .Show with a Frame...
so do u know how could i do to open a frame with a button click?

timg
Earned some good credits
Earned some good credits
Posts: 148
Joined: Mon Jan 23, 2006 6:52 pm

Post by timg » Fri Oct 24, 2008 6:13 pm

Mavverick wrote:yea.. i tried this:

Code: Select all

/*
 * btnOKClick
 */
void RobotsDlg::btnOKClick(wxCommandEvent& event)
{
      // insert your code here
      int GetSelection();
      if (rdbNumRobots->GetSelection() == 0)
      {
          JuntasFrm TempJuntasFrm(this);
          TempJuntasFrm.Show();
      }
)
and it's compiling.. but when i press the button OK, it's not opening my Juntas frame..
do u have any idea why? is it something wrong in my code?
Is the frame supposed to be Modal? Otherwise, I think your form object will quickly drop out of scope and be deleted.

Mavverick
Earned a small fee
Earned a small fee
Posts: 18
Joined: Tue Sep 09, 2008 12:14 pm
Location: Brasil

Post by Mavverick » Fri Oct 24, 2008 7:27 pm

ah yea.. that is what happens i think!!

like.. when the program starts, a dialog opens.. so there u have 2 options, u are gonna choose one e click OK..
now that dialog closes (i forgot about that.. i didnt make it to close yet) and it opens the frame!
does it have to be modal?? if yes, how can i do that? or if i want to be modal, i have to use a wxdialog?

timg
Earned some good credits
Earned some good credits
Posts: 148
Joined: Mon Jan 23, 2006 6:52 pm

Post by timg » Fri Oct 24, 2008 8:42 pm

No, it doesn't have to be Modal. If you want to do what you describe, maybe you should have a member variable in your
application and create the frame using new in your dialog.

Something like this:

Code: Select all

//declared in myApp?
JuntasFrm*   myJuntasFrm;

void RobotsDlg::btnOKClick(wxCommandEvent& event)
{
      // insert your code here
      int GetSelection();
      if (rdbNumRobots->GetSelection() == 0)
      {
          myJuntasFrm = new JuntasFrm(this);
          myJuntasFrm->Show();
      }
)

Mavverick
Earned a small fee
Earned a small fee
Posts: 18
Joined: Tue Sep 09, 2008 12:14 pm
Location: Brasil

Post by Mavverick » Fri Oct 24, 2008 10:16 pm

Oh man.. almost there!
i wrote this:

Code: Select all

void RobotsDlg::btnOKClick(wxCommandEvent& event)
{
    // insert your code here
    JuntasFrm*   myJuntasFrm;
    JuntasUmFrm*   myJuntasUmFrm;
    int GetSelection();
    if (rdbNumRobots->GetSelection() == 1)
    {
        myJuntasFrm = new JuntasFrm(this);
        myJuntasFrm->Show();
    }
    else
    {
        myJuntasUmFrm = new JuntasUmFrm(this);
        myJuntasUmFrm->Show();
    }
    Destroy();
}
And that thing still happens: the frames show up, but disappear in a fraction of seconds =(
Do u know what is still wrong?
Thanks for the help until now!

timg
Earned some good credits
Earned some good credits
Posts: 148
Joined: Mon Jan 23, 2006 6:52 pm

Post by timg » Fri Oct 24, 2008 10:30 pm

It's probably deleting your pointers when the Dialog is detroyed and deleting whatever it is that they are pointing to.

Try putting the pointer variables into whatever it is that creates the Dialog.

Mavverick
Earned a small fee
Earned a small fee
Posts: 18
Joined: Tue Sep 09, 2008 12:14 pm
Location: Brasil

Post by Mavverick » Tue Oct 28, 2008 11:31 am

I solved it by not using Destroy() anymore..
Thank you very much for the help!

Post Reply