Tutorials Forums
     Tutorials Videos
        Sign Up Now For FREE
Welcome, Guest
Username Password: Remember me

Iterate and Access the Properties of all the....
(1 viewing) (1) Guest
VB.NET HELP, VB.NET TUTORIALS, VB.NET CODE, VB.NET PROGRAMMING, VB.NET

Visual Basic.NET is the most recent generation of Visual Basic. Developers will be pleased to note that its new features include inheritance, method overloading, structured exception handling, and more. These capabilities make it easier than ever to create .NET applications, including Windows applications, web services, and web applications. The articles in this section give you all the tips you need to work wit this useful language.
  • Page:
  • 1

TOPIC: Iterate and Access the Properties of all the....

Iterate and Access the Properties of all the.... 09 Dec 2009 15:15 #65

This snippet iterates through a form to find the type of control you specified and lets you access the properties of all the found controls.

 
Public Class Utilities
 
Public Function Iteration(ByVal formToIterate As Form, _
ByVal TypeOfControlToGet As Control) As List(Of Control)
 
' Create List of Array to store the iterated controls
Dim arrControls As New List(Of Control)
Dim ctrl As Control
 
'
Iterate/Loop through the form,
' searching for the specified type of control to get
For Each ctrl In formToIterate.Controls
 
'
Store the control
If ctrl.GetType Is TypeOfControlToGet.GetType Then
TypeOfControlToGet = ctrl
arrControls.Add(TypeOfControlToGet)
End If
 
Next
 
Return arrControls
 
End Function
 
End Class
 
 
 
' Usage Example:
'
Change all the Text Property of all the Label
' Controls in the current form
 
Public Class Form1
 
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles Me.Load
 
Dim utilityClass As New Utilities
Dim xlabel As New Label
Dim arrayList As List(Of Control)
 
'
This will get all the Label control from the form
arrayList = utilityClass.Iteration(Me, xlabel)
 
' Change text displayed of all the labels in the form
For Each c As Control In arrayList
c.Text = "Sample Text"
Next
 
End Sub
 
End Class
 
 
  • CE
  • OFFLINE
  • Administrator
  • Posts: 197
  • Karma: 78
CodersEngine
  • Page:
  • 1
Time to create page: 0.26 seconds