Page 1 of 4

Main frame collecting Dialog info?

Posted: Tue Feb 20, 2007 2:18 am
by FlyingIsFun1217
Hey, me again :P

I need to do something that I don't think I've seen discussed before. Can't remember though.

Anyway, I've got a ListCtrl in the main frame, and a buncha TextCtrl's in the dialog. How can I collect the value from a dialog and pass it to the main frame to collect the info and enter it in the ListCtrl?

Thanks again!
FlyingIsFun1217

Re: Main frame collecting Dialog info?

Posted: Tue Feb 20, 2007 2:22 am
by Auria
FlyingIsFun1217 wrote: Anyway, I've got a ListCtrl in the main frame, and a buncha TextCtrl's in the dialog. How can I collect the value from a dialog and pass it to the main frame to collect the info and enter it in the ListCtrl?
Many ways to do that - you can just have the wxDialog check for some events (choose which ones) and on those events call MainFrame->setMyData() etc.

Posted: Tue Feb 20, 2007 8:50 am
by PhoenixPl
Personally I prefare structures that are filled by dialog on MyDialog::GetMyData().

Re: Main frame collecting Dialog info?

Posted: Tue Feb 20, 2007 9:24 pm
by FlyingIsFun1217
Auria wrote:
FlyingIsFun1217 wrote: Anyway, I've got a ListCtrl in the main frame, and a buncha TextCtrl's in the dialog. How can I collect the value from a dialog and pass it to the main frame to collect the info and enter it in the ListCtrl?
Many ways to do that - you can just have the wxDialog check for some events (choose which ones) and on those events call MainFrame->setMyData() etc.
Why would I have the dialog check for events? Wouldn't the Frame do that?
Also, would I be able to make the frame see when the dialog closes, and have it refresh the ListCtrl?

Thanks!
FlyingIsFun1217

Posted: Wed Feb 21, 2007 5:21 pm
by FlyingIsFun1217
Can somebody show me an example at least?

Thanks!
FlyingIsFun1217

Re: Main frame collecting Dialog info?

Posted: Wed Feb 21, 2007 7:09 pm
by Auria
FlyingIsFun1217 wrote: Why would I have the dialog check for events?
To know when the user closes it!

Well at least that's how i do it in my project and it works fine.

Re: Main frame collecting Dialog info?

Posted: Wed Feb 21, 2007 9:24 pm
by FlyingIsFun1217
Auria wrote:
FlyingIsFun1217 wrote: Why would I have the dialog check for events?
To know when the user closes it!

Well at least that's how i do it in my project and it works fine.
Ok, I see what you are saying; I would need to add something to do to the close event in order to collect it. But what can I use to catch that close from the main frame?

Thanks again!
FlyingIsFun1217

Re: Main frame collecting Dialog info?

Posted: Wed Feb 21, 2007 9:29 pm
by Auria
FlyingIsFun1217 wrote:
Auria wrote:
FlyingIsFun1217 wrote: Why would I have the dialog check for events?
To know when the user closes it!

Well at least that's how i do it in my project and it works fine.
Ok, I see what you are saying; I would need to add something to do to the close event in order to collect it. But what can I use to catch that close from the main frame?

Thanks again!
FlyingIsFun1217
perhaps look into Connectso that Dialog events are sent to the main frame.

but anyway as i already said you can just add a SetData method to your main frame and have the dialog call that one (assuming you derived both wxFrame and wxDialog)

Posted: Wed Feb 21, 2007 11:16 pm
by FlyingIsFun1217
As to the SetData method, that would be something that the Frame would do, right? So before it does that, it needs to collect the info from the dialog? Doesn't that defeat the purpose?

As to 'Connect', can you send me a link to a doc about it?

Thanks again, very helpful :)
FlyingIsFun1217

Posted: Wed Feb 21, 2007 11:47 pm
by Auria
FlyingIsFun1217 wrote:As to the SetData method, that would be something that the Frame would do, right? So before it does that, it needs to collect the info from the dialog? Doesn't that defeat the purpose?
Hm we don't seem to understand each other :lol:

Pseudo-code: (it doesn,t work, it's just an example of how to proceed)

Code: Select all

class MyFrame : wxFrame
{

public:
void setData(wxString a, int b, float c);

MyFrame : wxFrame(...)
{
  Show();
}

void onSomeEvent()
{
MyDialog* x =new MyDialog(this);
}

};

class MyDialog : wxDialog
{

MyFrame* parent_frame;

public:
 MyDialog(MyFrame* parent) : wxDialog(parent)
 {
/// ---- HERE
    parent_frame = parent;
/// ----

    Show();
  }

 void onOKClicked()
  {

    parent_frame -> SetData( z->GetValue(), y->GetValue(), x->GetValue() );
    Hide();
  }

};
As to 'Connect', can you send me a link to a doc about it?


http://wxwidgets.blogspot.com/2007/01/i ... nnect.html

Posted: Thu Feb 22, 2007 9:36 pm
by FlyingIsFun1217
Auria wrote:
FlyingIsFun1217 wrote:As to the SetData method, that would be something that the Frame would do, right? So before it does that, it needs to collect the info from the dialog? Doesn't that defeat the purpose?
Hm we don't seem to understand each other :lol:
Yeah, I'm losing it :P

Code: Select all

    parent_frame -> SetData( z->GetValue(), y->GetValue(), x->GetValue() );
Ok, I see how I would be setting it up, and that really does seem very easy!
Only thing is, your getting the values and passing them on to the main frame, how does it know what to do with those values?

Thanks again, I really appreciate it :)
FlyingIsFun1217

Posted: Thu Feb 22, 2007 9:40 pm
by Auria
FlyingIsFun1217 wrote: your getting the values and passing them on to the main frame, how does it know what to do with those values?
Well you needs to implement a SetData method that does whatever you want it to do :? i don't get the question, i suppose you know how to write a method in C++?? :lol: what don't you understand?

Posted: Thu Feb 22, 2007 9:45 pm
by FlyingIsFun1217
Auria wrote:i suppose you know how to write a method in C++?
Well, actually, no. Gotta remember I'm new to the language, and as can be seen, I went down the wrong path and started learning wxWidgets before I knew enough c++.

Now we know what the root of the problem is! I'll try looking it up and study it for a while.

Thanks!
FlyingIsFun1217

Posted: Thu Feb 22, 2007 9:50 pm
by Auria
FlyingIsFun1217 wrote:
Auria wrote:i suppose you know how to write a method in C++?
Well, actually, no. Gotta remember I'm new to the language, and as can be seen, I went down the wrong path and started learning wxWidgets before I knew enough c++.

Now we know what the root of the problem is! I'll try looking it up and study it for a while.

Thanks!
FlyingIsFun1217
Okay i didn't know you were new to C++ - in my imaginary world beginners learn the language before trying libs they cannot understand, however i don't even do it myself ;)

but writing a method is not hard, just looking at some docs should help you

Posted: Thu Feb 22, 2007 9:52 pm
by FlyingIsFun1217
Auria wrote: but writing a method is not hard, just looking at some docs should help you
Anything in particular that you could point me too?

Thanks :P
FlyingIsFun1217