By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 1,454 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

loop on controls in a container

P: n/a

Hi,

Is it possible (in vb.net with WinForms) to loop throw controls inside a
container (form or panel) sorting the controls on a property (.tabindex
for example) ?

My problem : on several forms (or panels), i have many controls
(inherited controls from base controls : MyTextbox, MyCombobox ..). I
add a new property on these controls : .BeginningGroup (boolean : yes or
no).

The focus is on a control in the form. I want with the key PageDown to
move the focus on the first controls following having the
property.Beginning (=yes), and with the key Page Up on the first
previous.

For that, i must loop on controls sorting by .tabindex.

i think it is :
dim ctl as control
for each ctl in MyForm.controls
.. but with a sort by Tabindex and a start value

with an arraylist or collection ??

Can you help me ?

Thanks for advance

Dominique

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
In the Form Load event you could add the panels to an arraylist, in the order
you want to sort through them. The arraylist has an index property. You
need to also add a handler for Me.KeyDown to capture the page up and page
down keys, and you need to keep track of the current index so you can get to
the current panel. Remember to set KeyPreview to true for the form. Each
panel has a controls collection that you can loop through.

dim Ctl as Control
For each Ctl in CurrentPanel.Controls
If Ctl.gettype.name = "MyTextBox" then
dim MyTxt as MyTextBox = directcast(Ctl, MyTextBox)
If MyTxt.Beginning = true then
MyTxt.focus
Exit For
end if
end if
Next

You don't have to worry about sorting the controls within the panel, as long
as you are only setting the Beginning property to true for one of the
controls. When that control is found in the loop, focus on it and exit the
loop.

cf******@charlesfarriersoftware.com

"dominique" wrote:

Hi,

Is it possible (in vb.net with WinForms) to loop throw controls inside a
container (form or panel) sorting the controls on a property (.tabindex
for example) ?

My problem : on several forms (or panels), i have many controls
(inherited controls from base controls : MyTextbox, MyCombobox ..). I
add a new property on these controls : .BeginningGroup (boolean : yes or
no).

The focus is on a control in the form. I want with the key PageDown to
move the focus on the first controls following having the
property.Beginning (=yes), and with the key Page Up on the first
previous.

For that, i must loop on controls sorting by .tabindex.

i think it is :
dim ctl as control
for each ctl in MyForm.controls
.. but with a sort by Tabindex and a start value

with an arraylist or collection ??

Can you help me ?

Thanks for advance

Dominique

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #2

P: n/a
Thanks Charlie for your answer,

I can have several controls with the Beginning property to true in the
same container. It is useful to move the focus at the beginning of
groups of controls (without use groupbox).

So i must use your first solution : an array list sorted with index
property and keep track of current index.
But i think this array list must contain the controls inside panels
with, why not, a new property giving the index of the panel in use
because, it is true, i can also have several panels (or tabs) on one
form.

What do you think about that ? have you any idea to code that ?

Dominique

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #3

P: n/a
Thanks Charlie for your answer,

I can have several controls with the Beginning property to true in the
same container. It is useful to move the focus at the beginning of
groups of controls (without use groupbox).

So i must use your first solution : an array list sorted with index
property and keep track of current index.
But i think this array list must contain the controls inside panels
with, why not, a new property giving the index of the panel in use
because, it is true, i can also have several panels (or tabs) on one
form.

What do you think about that ? have you any idea to code that ?

Dominique

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #4

P: n/a
Let's see if I understand the problem:

You have usercontrols in several panels on the form. You want to use
PageUp/PageDown to scroll between panels. When you scroll to a panel, you
want to focus on a designated "first" usercontrol.

Assuming that is right,
You would capture the page up/down keys in the form's KeyDown event.
You would put the panels of the form into an ArrayList in the Form Load
event, in the order in which you want to navigate them.
You would loop through the controls of the panel to find the one with a
property that designates that control as being first. That could be the
tabindex property, or a custom property of the control. You do not have to
pre-sort the usercontrols in an arraylist, just the panels

Then you would focus to that control.

cf******@charlesfarriersoftware.com

"dominique" wrote:

Hi,

Is it possible (in vb.net with WinForms) to loop throw controls inside a
container (form or panel) sorting the controls on a property (.tabindex
for example) ?

My problem : on several forms (or panels), i have many controls
(inherited controls from base controls : MyTextbox, MyCombobox ..). I
add a new property on these controls : .BeginningGroup (boolean : yes or
no).

The focus is on a control in the form. I want with the key PageDown to
move the focus on the first controls following having the
property.Beginning (=yes), and with the key Page Up on the first
previous.

For that, i must loop on controls sorting by .tabindex.

i think it is :
dim ctl as control
for each ctl in MyForm.controls
.. but with a sort by Tabindex and a start value

with an arraylist or collection ??

Can you help me ?

Thanks for advance

Dominique

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #5

P: n/a
Let's see if I understand the problem:

You have usercontrols in several panels on the form. You want to use
PageUp/PageDown to scroll between panels. When you scroll to a panel, you
want to focus on a designated "first" usercontrol.

Assuming that is right,
You would capture the page up/down keys in the form's KeyDown event.
You would put the panels of the form into an ArrayList in the Form Load
event, in the order in which you want to navigate them.
You would loop through the controls of the panel to find the one with a
property that designates that control as being first. That could be the
tabindex property, or a custom property of the control. You do not have to
pre-sort the usercontrols in an arraylist, just the panels

Then you would focus to that control.

cf******@charlesfarriersoftware.com

"dominique" wrote:

Hi,

Is it possible (in vb.net with WinForms) to loop throw controls inside a
container (form or panel) sorting the controls on a property (.tabindex
for example) ?

My problem : on several forms (or panels), i have many controls
(inherited controls from base controls : MyTextbox, MyCombobox ..). I
add a new property on these controls : .BeginningGroup (boolean : yes or
no).

The focus is on a control in the form. I want with the key PageDown to
move the focus on the first controls following having the
property.Beginning (=yes), and with the key Page Up on the first
previous.

For that, i must loop on controls sorting by .tabindex.

i think it is :
dim ctl as control
for each ctl in MyForm.controls
.. but with a sort by Tabindex and a start value

with an arraylist or collection ??

Can you help me ?

Thanks for advance

Dominique

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #6

P: n/a
Thanks, Charlie, for your answer,

you wrote :
"You have usercontrols in several panels on the form."
Yes i can but it is not realy my problem, suppose i have only one panel.

"You want to use PageUp/PageDown to scroll between panels."
No, i want to use PageUp/PageDown to scroll between controls inside the
same panel.

For example, in a form i have 30 textbox (6 groups of 5 textbox each)
but without groupbox.
TextBox01 have the property .BeginningGroup=true (idem for TextBox6,
TextBox11, TextBox16, TextBox21 and TextBox26).
Now the focus is on Textbox23, i want with PageDown key to move focus on
TextBox26 and with PageUp key to move focus on TextBox21. It is the same
if the focus was at first on TextBox22, TextBox24 or TextBox25.
And more .. i want generic code which can be use for any form not for a
special form (then i can't write TextBox21.focus).

I get my customers used to that with softwares i wrote with PDS Basic
7.1. They use many times the keyboard and not often the mouse. Believe
me, it is very useful to use Page Down and Page Up like that. I use also
arrow down instead of Tab and arrow up instead of shift+tab (one key
instead of two) and all direction keys with the same hand. It is quicker
to input data.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #7

P: n/a
Thanks, Charlie, for your answer,

you wrote :
"You have usercontrols in several panels on the form."
Yes i can but it is not realy my problem, suppose i have only one panel.

"You want to use PageUp/PageDown to scroll between panels."
No, i want to use PageUp/PageDown to scroll between controls inside the
same panel.

For example, in a form i have 30 textbox (6 groups of 5 textbox each)
but without groupbox.
TextBox01 have the property .BeginningGroup=true (idem for TextBox6,
TextBox11, TextBox16, TextBox21 and TextBox26).
Now the focus is on Textbox23, i want with PageDown key to move focus on
TextBox26 and with PageUp key to move focus on TextBox21. It is the same
if the focus was at first on TextBox22, TextBox24 or TextBox25.
And more .. i want generic code which can be use for any form not for a
special form (then i can't write TextBox21.focus).

I get my customers used to that with softwares i wrote with PDS Basic
7.1. They use many times the keyboard and not often the mouse. Believe
me, it is very useful to use Page Down and Page Up like that. I use also
arrow down instead of Tab and arrow up instead of shift+tab (one key
instead of two) and all direction keys with the same hand. It is quicker
to input data.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #8

P: n/a
Dominique,

A UserControl would probably offer the best solution. It would offer
flexibility and repeatability. Design time changes are reflected instantly
in the user control. When you would change "Columns" or "Rows", the number
of columns or rows would instantly be updated in the design time form for
that instance of the UserControl.

The contained controls could be a mix of say, textboxes and comboboxes, or
they could be inherited controls. The contained controls would be indexed,
making navigation much simpler and probably more reliable. The keyboard
navigation you wrote about would be managed from within the UserControl.

The values would probably best be exposed through a two-dimensional string
array. If you have calculations, the user control could raise events to the
form, where the calculations would take place, and the event could also
handle where to insert the calculation results.

You can reach me by e-mail at
cf******@charlesfarriersoftware.com
or
ch************@yahoo.com


"dominique" wrote:
Thanks, Charlie, for your answer,

you wrote :
"You have usercontrols in several panels on the form."
Yes i can but it is not realy my problem, suppose i have only one panel.

"You want to use PageUp/PageDown to scroll between panels."
No, i want to use PageUp/PageDown to scroll between controls inside the
same panel.

For example, in a form i have 30 textbox (6 groups of 5 textbox each)
but without groupbox.
TextBox01 have the property .BeginningGroup=true (idem for TextBox6,
TextBox11, TextBox16, TextBox21 and TextBox26).
Now the focus is on Textbox23, i want with PageDown key to move focus on
TextBox26 and with PageUp key to move focus on TextBox21. It is the same
if the focus was at first on TextBox22, TextBox24 or TextBox25.
And more .. i want generic code which can be use for any form not for a
special form (then i can't write TextBox21.focus).

I get my customers used to that with softwares i wrote with PDS Basic
7.1. They use many times the keyboard and not often the mouse. Believe
me, it is very useful to use Page Down and Page Up like that. I use also
arrow down instead of Tab and arrow up instead of shift+tab (one key
instead of two) and all direction keys with the same hand. It is quicker
to input data.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.