if i type in textbox 1,3 then checkbox1 and checkbox3 will be disabled not checked !

后端 未结 1 689
感动是毒
感动是毒 2021-01-29 07:43

if i type in textbox 1,3 then checkbox1 and checkbox3 will be disabled not checked !!

The coding i provide below is working but ,...it chekec the cjeckoxes according to

1条回答
  •  一生所求
    2021-01-29 08:12

    I assume that you want those checkboxes disabled that are comma separated listed in the TextBox and the other checkboxes enabled. (improved a little bit your code, because originally it came from me)

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Dim separator As Char = ","c
        Dim allIIDs As New List(Of String)
        If TextBox1.Text.Length <> 0 Then
            For Each strNum As String In TextBox1.Text.Split(separator)
                Dim num As Int32
                If Int32.TryParse(strNum, num) Then
                    allIIDs.Add(strNum)
                End If
            Next
        End If
        allIIDs.Sort()
        For Each control As Control In Panel1.Controls
            If TypeOf control Is CheckBox Then
                Dim chk As CheckBox = DirectCast(control, CheckBox)
                chk.Enabled = allIIDs.BinarySearch(chk.Text) < 0
            End If
        Next
    End Sub
    

    Remember to set AutoPostBack="false" to TextBox1, otherwise you need 2 Postbacks to see the disabled state of the checkboxes.

    0 讨论(0)
提交回复
热议问题