473,795 Members | 2,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Beginn ing (=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 2528
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.Co ntrols
If Ctl.gettype.nam e = "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******@charle sfarriersoftwar e.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.Beginn ing (=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******@charle sfarriersoftwar e.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.Beginn ing (=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******@charle sfarriersoftwar e.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.Beginn ing (=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******@charle sfarriersoftwar e.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
2584
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 controls in a specific frame on a form and unselects the option buttons. .NET barks at this line of code: thiscontrol.value = False Private Sub UnSelectOpts(ByVal passedframeCaption As String) Dim thiscontrol As Control For Each thiscontrol In Me...
6
10296
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 = ""; MessageBox.Show(c.Name.ToString());
3
351
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 controls in a specific frame on a form and unselects the option buttons. .NET barks at this line of code: thiscontrol.value = False Private Sub UnSelectOpts(ByVal passedframeCaption As String) Dim thiscontrol As Control For Each thiscontrol In Me...
1
2623
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 during runtime. I also had a generic list to fetch few items. Number of item that i got from the list will be the number of template that being created during runtime(eg : if the list return 3 items, meaning there will be 3 template field created)....
0
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10439
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10215
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10165
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.