I've got some listboxes with labels on them and I want the label above each listbox to be hidden when the listbox is hidden. Right now I'm giving them matching tags and then just looping to search for the correct one:
There has to be a better way.Code:'this subroutine covers concealing all listboxes Private Sub DisableListboxes(sender As Object, e As EventArgs) Handles Listbox1.EnabledChanged, _ Listbox2.EnabledChanged, Listbox3.EnabledChanged 'the name of the listbox that raised the sub Dim CurrentList As ListBox = DirectCast(sender, ListBox) 'finds the label associated with that listbox Dim CurrentLabel As Label = Nothing For Each lb As Control In CurrentList.Parent.Controls If TypeOf lb Is Label Then If CStr(lb.Tag) = CStr(CurrentList.Tag) Then 'it's the correct one CurrentLabel = DirectCast(lb, Label) End If End If Next lb If CurrentList.Enabled = False Then 'conceals the label CurrentLabel.Enabled = False Else 'reveals the label CurrentLabel.Enabled = True End If End Sub




Reply With Quote