Sunday, April 15, 2012

GET ALL CONTROL INSIDE FORM AND SET CONTROLS PROPERTY

Public Shared Function GetControls(ByVal form As Control) As List(Of Control)
Dim controlList = New List(Of Control)()
For Each childControl As Control In form.Controls
' Recurse child controls.
controlList.AddRange(GetControls(childControl))
controlList.Add(childControl)
Next
Return controlList
End Function


Private Sub SetControls(ByVal _controls As List(Of Control), ByRef dtControrName As DataTable)
Dim cControl As Control

For Each cControl In _controls
If (TypeOf cControl Is Button) Then

For i As Integer = 0 To dtControrName.Rows.Count - 1

If (cControl.Name = dtControrName.Rows(i)(0).ToString) Then
cControl.Enabled = True
Exit For
Else
cControl.Enabled = False
End If
Next
End If

Next cControl
End Sub


Dim controlList = New List(Of Control)()
controlList = GetControls(_form)//Parametar formname
SetControls(controlList, dtGET_FORM_PERMISSION)

No comments:

Post a Comment