468,770 Members | 2,352 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,770 developers. It's quick & easy.

select only one checkbox at a time

hi,
im srikanth, i having a datagrid in that i have 5 checkboxes in windows application(C#.net) i want to check only one checkbox at a time and remaining should not be selected


regards,

srikanth
Nov 18 '08 #1
4 6721
r035198x
13,262 8TB
You are using the wrong control then. Use a RadioButton instead.
Nov 18 '08 #2
balabaster
797 Expert 512MB
Or something like this could work... (depending on your form design...)

Expand|Select|Wrap|Line Numbers
  1.     Protected Sub CheckBoxHandler(ByVal Sender As Object, ByVal e As EventArgs) _
  2.     Handles CheckBox1.Checked, Checkbox2.Checked, CheckBox3.Checked, CheckBox4.Checked, CheckBox5.Checked
  3.  
  4.         Dim ThisCheckBox As CheckBox = DirectCast(Sender, CheckBox)
  5.         ThisCheckBox.Checked = Not ThisCheckBox.Checked
  6.  
  7.         For Each CrntControl As Control In Me.Controls
  8.             If TypeOf CrntControl Is CheckBox And Not CrntControl Is ThisCheckBox Then
  9.                 If ThisCheckBox.Checked Then
  10.                     DirectCast(CrntControl, CheckBox).Checked = Not ThisCheckBox.Checked
  11.                 End If
  12.             End If
  13.         Next
  14.  
  15.     End Sub
Nov 18 '08 #3
You are using the wrong control then. Use a RadioButton instead.
hey i know that but my requirement is to use checkbox
Nov 20 '08 #4
r035198x
13,262 8TB
hey i know that but my requirement is to use checkbox
Why do you have to use checkbox? Is it homework?
Nov 20 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by RC | last post: by
5 posts views Thread by _andrea.l | last post: by
reply views Thread by Peter Afonin | last post: by
2 posts views Thread by simon.wilkinson | last post: by
1 post views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.