Main frame collecting Dialog info?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Main frame collecting Dialog info?

Post by FlyingIsFun1217 » Tue Feb 20, 2007 2:18 am

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

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Re: Main frame collecting Dialog info?

Post by Auria » Tue Feb 20, 2007 2:22 am

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.

PhoenixPl
I live to help wx-kind
I live to help wx-kind
Posts: 179
Joined: Wed Feb 15, 2006 9:26 am

Post by PhoenixPl » Tue Feb 20, 2007 8:50 am

Personally I prefare structures that are filled by dialog on MyDialog::GetMyData().

FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Re: Main frame collecting Dialog info?

Post by FlyingIsFun1217 » Tue Feb 20, 2007 9:24 pm

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

FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Post by FlyingIsFun1217 » Wed Feb 21, 2007 5:21 pm

Can somebody show me an example at least?

Thanks!
FlyingIsFun1217

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Re: Main frame collecting Dialog info?

Post by Auria » Wed Feb 21, 2007 7:09 pm

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.

FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Re: Main frame collecting Dialog info?

Post by FlyingIsFun1217 » Wed Feb 21, 2007 9:24 pm

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

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Re: Main frame collecting Dialog info?

Post by Auria » Wed Feb 21, 2007 9:29 pm

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)

FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Post by FlyingIsFun1217 » Wed Feb 21, 2007 11:16 pm

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

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Wed Feb 21, 2007 11:47 pm

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
Last edited by Auria on Tue Mar 27, 2007 11:42 pm, edited 4 times in total.

FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Post by FlyingIsFun1217 » Thu Feb 22, 2007 9:36 pm

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

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Thu Feb 22, 2007 9:40 pm

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?

FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Post by FlyingIsFun1217 » Thu Feb 22, 2007 9:45 pm

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

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Thu Feb 22, 2007 9:50 pm

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
Last edited by Auria on Thu Feb 22, 2007 9:54 pm, edited 1 time in total.

FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Post by FlyingIsFun1217 » Thu Feb 22, 2007 9:52 pm

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

Post Reply