John (Yiannis) Toutountzoglou
asked on
Public Event in Public Function
I am trying to create a Function that Counts Controls with the same Tag
Hi to all
These controls are inside a ChildControl like GroupBox which they are Created in a parent Container like TabControl.TabPage
This Function should be call in a form load event
Then in this Function i need to add a TextChange Event handler Which detects how many of these controls with the same tag are different than an empty string (Not empty).
I will Post an example how it works in private
For Each GroupBoxCtl In Me.TabControl1.TabPages(0).Controls
If TypeOf GroupBoxCtl Is GroupBox Then
For Each Xctl As Control In GroupBoxCtl.Controls
If Xctl.Tag = "Required" Then
AddHandler Xctl.TextChanged, AddressOf Xctl_TextChanged
x += 1
End If
Next
End If
Next
For Each GroupBoxCtl In Me.TabControl1.TabPages(0).Controls
If TypeOf GroupBoxCtl Is TextBox Then
If GroupBoxCtl.Tag = "Required" Then
AddHandler GroupBoxCtl.TextChanged, AddressOf Xctl_TextChanged
y += 1
End If
End If
Next
Dim x As Integer = 0
Dim y As Integer = 0
Private Sub Xctl_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim j As Integer = 0
Dim k As Integer = 0
For Each GroupBoxCtl In Me.TabControl1.TabPages(0).Controls
If TypeOf GroupBoxCtl Is GroupBox Then
For Each Xctl As Control In GroupBoxCtl.Controls
If Xctl.Tag = "Required" Then
If Xctl.Text <> "" Then
j += 1
Me.ContinueToNextTab2.Text = "There are " & (x + y) - (j + k) & " Remaining Required Fields"
End If
End If
Next
End If
Next
For Each GroupBoxCtl In Me.TabControl1.TabPages(0).Controls
If TypeOf GroupBoxCtl Is TextBox Then
If GroupBoxCtl.Tag = "Required" Then
If GroupBoxCtl.text <> "" Then
k += 1
Me.ContinueToNextTab2.Text = "There are " & (x + y) - (j + k) & " Remaining Required Fields"
End If
End If
End If
Next
If j + k = x + y Then
Me.ContinueToNextTab2.Text = "You may proceed"
Else
Me.ContinueToNextTab2.Text = "There are " & (x + y) - (j + k) & " Remaining Required Fields"
End If
End Sub
The above counts controls inside a tabpage and groupBoxes which are also in this tabpageNow i need this as a Function to Public
Module ControlsFunctions
Public Event TextChanged As CountControlsTagsEventHandler
Public Function CountCertainControlsTag(ByVal ParentContainer As Control, ByVal ChildControl As Control, ByVal StringTag As String) As Integer
Dim i As Integer = 0
Dim ctl As Control
For Each ctl In ParentContainer.Controls
If ctl.[GetType]() Is GetType(GroupBox) Then
For Each ChildControl In ctl.Controls
If ChildControl.Tag = StringTag Then
AddHandler ChildControl.TextChanged, New EventHandler(AddressOf ChildControl_TextChanged)
i += 1
End If
Next
End If
Next
Return i
End Function
Public Sub ChildControl_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
RaiseEvent TextChanged() 'What do i have to reference here....
End Sub
Public Delegate Sub CountControlsTagsEventHandler(ByVal ParentContainer As Control, ByVal ChildControl As Control, ByVal StringTag As String)
End Module
How can i build the TextChange Event
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you Mike...