473,837 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Just trying to iterate over controls...

A
HI all,

I am trying to iterate over all the controls on my form and if a control IS
A textbox then I want to enter the If statement. So far I can't get it to
work...here is the code...any help?

For Each c As Control In Me.Controls

If c.GetType() Is System.Type.Get Type("TextBox") Then

Do something useful....

End If

Next
Nov 20 '05 #1
2 1155

"A" <no****@hotmail .com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
HI all,

I am trying to iterate over all the controls on my form and if a control IS A textbox then I want to enter the If statement. So far I can't get it to
work...here is the code...any help?

For Each c As Control In Me.Controls

If c.GetType() Is System.Type.Get Type("TextBox") Then

Do something useful....

End If

Next

Try this instead.

For Each objControl In Controls

If TypeOf (objControl) Is TextBox Then

objControl.Text = "Yippee!"

' or, something useful

End If

Hope this helps.
--
Peter [MVP Visual Developer]
Jack of all trades, master of none.

Next
Nov 20 '05 #2
Hi A,

It looks the same as from Peter, however this does as well the controls in
by intance a panel. When you do not have those take the one from Peter.

\\\\
Private Sub Form1_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
doYippy(Me)
End Sub
Private Sub doYippy(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Contr ols
If TypeOf ctr Is TextBox Then
ctr.Text = "Yippy"
End If
doYippy(ctr)
Next
End Sub
///
I hope this helps?

Cor
Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5362
by: Simon | last post by:
I've got a webform and many controls on it. I would like to iterate thru the control collection to get all the textboxes control to let me change the text property. Here is my code...for unknown reason, this loop iterates only 3 times! Help please! Thanks! Dim Control As Web.UI.Control Dim TextBox As System.Web.UI.WebControls.TextBox For Each Control In Controls If TypeOf (Control) Is System.Web.UI.WebControls.TextBox Then
2
2185
by: martin | last post by:
hi, I am using vb.net. I have wrote a data access class and one of my methods returns a dataset. I would like to iterate through this, although this is proving problematic for me. Can anybody please point out the addition that I would need to the follwoing code.
2
1962
by: James Doran | last post by:
Hello, I'd like to iterate through each Page of my ASP.NET project from within a Custom web control and access the Page.Controls collection. I've tried using Reflection on the web project assembly, but the controls collection count was zero. While this method gives details of the private controls in each page, I need access to actual instances of the controls to interrogate their individual properties.
2
1173
by: Tina | last post by:
I need to find all of the datagrids on a page. How can I iterate through all of the controls on a page to get their name and grab them as an object? thanks, T
2
1947
by: Oleg | last post by:
Let's say I rendered a bunch of controls with the same name and different IDs. On postback, can I somehow iterate through these controls (checkboxes in this case, but could be dropdown controls in the future) and get their values and IDs with all this done in the code behind page? A small example would be appreciated. Thanks, Oleg
14
4050
by: Jan Nielsen | last post by:
Hi In Microsoft Access it is possible to write code like this Sub test() DoCmd.OpenForm "TestForm", acDesign Dim a As Control For Each a In Forms("TestForm").Controls Do stuff Next End Sub
7
5052
by: Rich | last post by:
Hello, I have a form with 5 textboxes named txt0, txt1, txt2, txt3, tx4. In VB6 I could iterate through these with For i = 0 to 4 debug.print Me.controls("txt" & i).Name Next
4
6599
by: romy | last post by:
Hi In VB.net I have a set of linkButtons controls in a form , which I want to iterate on them and change their text property. How it's done ? thanks
9
2906
Shashi Sadasivan
by: Shashi Sadasivan | last post by:
In my current application, I have to set cettain defaults to controls that are displayed or are used. so i have a class to which i send the form as a control, and iterate through each of its controls and child controls However, I have to also edit the Interval property of any timers present in the form. Timers come under the Windows.Forms.Timer namespace and i am currently iterating through all the Controls in the form. How would I...
0
9682
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10570
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
10626
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
9402
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...
1
7806
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7001
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
5670
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5849
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4474
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.