Deathonly Deathonly - 4 months ago 29
Vb.net Question

Textbox Enabled True False

This is code am trying to solve

Dim i As Integer
i = ListBox1.SelectedIndex
If ListBox1.SelectedIndex = 0 Then
TextBox10.Enabled = False
TextBox25.Enabled = False
TextBox30.Enabled = False
TextBox40.Enabled = False
TextBox55.Enabled = False
TextBox65.Enabled = False
TextBox73.Enabled = False
TextBox84.Enabled = False
TextBox95.Enabled = False
TextBox100.Enabled = False
TextBox185.Enabled = False
Else
TextBox(??).Enabled = True

End If


How to other textboxes to enable True?
I mean
10,25,30,40... 185 are false and all other textboes Enabled true ?

Answer

You can find control of type textbox and assign default enabled= true and then write your code to set enabled=false.

For Each c As Control In Me.Controls
If c.GetType Is GetType(TextBox) Then
    c.Enabled=true
End If
Next

OR  

Dim allTextBox As New List(Of Control)
For Each c As TextBox In FindControl(allTextBox, Me,GetType(TextBox))
    c.Enabled=true
Next

Public Shared Function FindControl(ByVal list As List(Of Control), ByVal parent As Control, ByVal ctrlType As System.Type) As List(Of Control)
    If parent Is Nothing Then Return list
    If parent.GetType Is ctrlType Then
        list.Add(parent)
    End If
    For Each child As Control In parent.Controls
        FindControl(list, child, ctrlType)
    Next
    Return list
End Function
Comments