Iterating through controls with control ID number

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.
Post Reply
Ugly!
Earned some good credits
Earned some good credits
Posts: 113
Joined: Mon May 09, 2005 5:11 am
Location: Argentina - BS AS

Iterating through controls with control ID number

Post by Ugly! » Mon May 09, 2005 5:20 am

Is there a way to iterate trought controls using the control's ID number.
I mean, if i have 20 checkboxes, is there a way to check the state of each one of them using the control ID and incremating this ID (asuming secuentials IDs numbers)???
I could do this with the win32 Api - SendMessage() function -, but i can't find a way to do this in wxWidgets yet.
Just a newbie - Too many interests, not too many time.

Windows XP SP2
Kubuntu GNU/Linux - Feisty
wxActiveRecordGenerator (aka wxARG) maintainer
Find it at wxCode

Cursor
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Aug 29, 2004 3:09 pm
Location: Grenoble, France
Contact:

Post by Cursor » Mon May 09, 2005 5:43 am

Yes you can by the wxWindow::FindWindowByID [1]. You have just to pass the parent adress and the ID, and it return the corresponding child wxWindow adress.

You can also use the wxWindow::GetChildren [2] but it is useless.

[1] : http://www.wxwidgets.org/manuals/2.6.0/ ... windowbyid
[2] : http://www.wxwidgets.org/manuals/2.6.0/ ... etchildren
What is little and green, witch go up and down ??
Yoda playing with the force.

Ugly!
Earned some good credits
Earned some good credits
Posts: 113
Joined: Mon May 09, 2005 5:11 am
Location: Argentina - BS AS

Post by Ugly! » Wed May 11, 2005 11:02 pm

Cursor wrote:Yes you can by the wxWindow::FindWindowByID [1]. You have just to pass the parent adress and the ID, and it return the corresponding child wxWindow adress.

You can also use the wxWindow::GetChildren [2] but it is useless.

[1] : http://www.wxwidgets.org/manuals/2.6.0/ ... windowbyid
[2] : http://www.wxwidgets.org/manuals/2.6.0/ ... etchildren
Thanx for answering
Now...lets see...how do i use the child address? Is it the pointer of the control? Do i have to cast it? Can u give a small example plz?

My idea is:

Code: Select all

wxCheckbox temp;

temp=wxWindow::FindWindowById(ID_CHECKBOX1,this);
if(temp->IsChecked()) count++;
Any way thanx a lot, i ll try and see what happens.
Just a newbie - Too many interests, not too many time.

Windows XP SP2
Kubuntu GNU/Linux - Feisty
wxActiveRecordGenerator (aka wxARG) maintainer
Find it at wxCode

Avi
Super wx Problem Solver
Super wx Problem Solver
Posts: 398
Joined: Mon Aug 30, 2004 9:27 pm
Location: Tel-Aviv, Israel

Post by Avi » Wed May 11, 2005 11:26 pm

Well, FindWindowsById returns a pointer!
Do it this way:

Code: Select all

wxCheckBox* temp = wxWindow::FindWindowById(ID_CHECKBOX1, this);
if(temp->IsChecked()) count++;

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Thu May 12, 2005 6:42 am

To be sure you can also use wxDynamicCast and wxStaticCast to see if the control you get the ID back from is a proper wxCheckBox control.

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

Post Reply