473,395 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

loop on controls in a container


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
8 2508
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Joe | last post by:
I'm wondering how to loop through controls in VB.NET. I have the code from VB6 ok, but I can't figure out how to do it correctly in .NET. This is an example from my VB6 code that loops through...
6
by: Thonglao Rud | last post by:
I'm trying to clear all textbox on the form. foreach (Control c in this.Controls) { //if (c.GetType() == typeof(TextBox)) if (c is TextBox) { // Found it c.Text = "";...
3
by: Joe | last post by:
I'm wondering how to loop through controls in VB.NET. I have the code from VB6 ok, but I can't figure out how to do it correctly in .NET. This is an example from my VB6 code that loops through...
1
by: zergziad | last post by:
Hi All, I really need help to solve my problem. My case is on looping through textbox in gridview. I had a gridview placed in my page. The gridview contains template field which I created it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.