Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir, i have a checkboxlist. i need that when i select one checkbox then all other checkbox are readonly property. it means. only one checkbox is selected at one time. untill i am not refresh my page. how can i do it.
Posted
Comments
hypermellow 11-Sep-14 5:38am    
Why the need to use a checkboxes, when the desired behaviour is provided by a radio button control?
... there is a RadioButtonList control available.

1 solution

Radio buttons has the way to achieve this result, but you still wanted to do this then, Handle the CheckBox.CheckedChanged event with the same sub for all four checkboxes

VB
Private Sub CheckBox1_CheckedChanged(sender As System.Object, e As System.EventArgs) _
    Handles CheckBox1.CheckedChanged, CheckBox2.CheckedChanged, CheckBox3.CheckedChanged, CheckBox4.CheckedChanged
    'cast sender
    Dim senderCheck As CheckBox = DirectCast(sender, CheckBox)

    'loop through all checkboxes
    For Each checkbox In {CheckBox1, CheckBox2, CheckBox3, CheckBox4}

        'only apply changes to non-sender  boxes
        If checkbox IsNot senderCheck Then

            'set property to opposite of sender so you can renable when unchecked
            checkbox.Enabled = Not senderCheck.Checked
        End If
    Next
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900