本文介绍了如果我在文本框中输入1,3,然后checkbox1和checkbox3将被禁用未选中!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在文本框中输入1,3,然后checkbox1和checkbox3将被禁用未签!

我在下面提供的编码工作,但,...它根据文本即(1,3),然后checkbox1和checkbox3将被选中文本chekec的cjeckoxes ..

..但我想,当我在文本框,然后checkbox1和checkbox3将被禁止输入1,3和处于未选中.........

任何机构可以更新我对这个code执行上述操作?

 保护小组的button1_Click(BYVAL发件人为对象,BYVAL E上System.EventArgs)把手Button1.Click
    昏暗的分隔符为char =,
    昏暗allIIDs作为新的列表(中的Int32)
    如果TextBox1.Text.Length<> 0,则
        对于每个strNum作为字符串在TextBox1.Text.Split(分离器)LT; BR>
            昏暗的NUM作为的Int32
            如果Int32.TryParse(strNum,NUM)则
                allIIDs.Add(NUM)            万一
        下一个
    万一
    allIIDs.Sort()
    对于每个控制作为控制在Panel1.Controls
        如果TypeOf运算控制是复选框然后
            DIM清洁香港作为复选框= DirectCast(控制,复选框)
            chk.Enabled = FALSE = allIIDs.BinarySearch(Int32.Parse(chk.Text))> -1
        万一
    下一个结束小组


解决方案

我假设你希望这些复选框禁用的用逗号在文本框中的分隔上市并启用其他复选框。 (改进一点点你的code,因为originally它来自我)

 保护小组的button1_Click(BYVAL发件人为对象,BYVAL E上EventArgs的)把手Button1.Click
    昏暗的分隔符为char =,C
    昏暗allIIDs作为新的列表(串)
    如果TextBox1.Text.Length<> 0,则
        对于每个strNum作为字符串在TextBox1.Text.Split(分隔符)
            昏暗的NUM作为的Int32
            如果Int32.TryParse(strNum,NUM)则
                allIIDs.Add(strNum)
            万一
        下一个
    万一
    allIIDs.Sort()
    对于每个控制作为控制在Panel1.Controls
        如果TypeOf运算控制是复选框然后
            DIM清洁香港作为复选框= DirectCast(控制,复选框)
            chk.Enabled = allIIDs.BinarySearch(chk.Text)LT; 0
        万一
    下一个
结束小组

记住要设置的AutoPostBack =FALSE来TextBox1的,否则需要2回传给看到的复选框的禁用状态。

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 the text in textbox i.e (1,3) then checkbox1 and checkbox3 will be checked ..

.. but i want when i type 1,3 in textbox then checkbox1 and checkbox3 will be disabled and remain unchecked .........

can any body update my this code to perform above operation ?

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim separator As Char = ","
    Dim allIIDs As New List(Of Int32)
    If TextBox1.Text.Length <> 0 Then
        For Each strNum As String In TextBox1.Text.Split(separator)<br>
            Dim num As Int32
            If Int32.TryParse(strNum, num) Then
                allIIDs.Add(num)

            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 = False = allIIDs.BinarySearch(Int32.Parse(chk.Text)) > -1
        End If
    Next

End Sub
解决方案

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.

这篇关于如果我在文本框中输入1,3,然后checkbox1和checkbox3将被禁用未选中!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 19:44