Click here to Skip to main content
15,904,823 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My application requirement is to check only one checkbox in a row . How can I achieve this ?
Posted
Updated 25-Mar-14 23:24pm
v3
Comments
CHill60 28-Feb-14 7:47am    
Maciej Los 28-Feb-14 7:52am    
That's the answer! My virtual 5!
Ni!E$H_WAGH 28-Feb-14 7:49am    
my application requirement is that I wanted the checkBox to behave like radiobutton

 
Share this answer
 
v3
Comments
CHill60 28-Feb-14 8:23am    
Note to OP and other readers ... if you were to follow the link Jas24 has posted, and then follow the 2nd Link on Solution 3 you will end up here ... http://stackoverflow.com/questions/5256967/how-to-check-only-one-item-in-checkedlistbox[^] ... which is actually a good answer for the OP.
Note to Jas24 ... you should have probably done that.
Tom Marvolo Riddle 28-Feb-14 8:29am    
solution updated.please see
CHill60 28-Feb-14 8:38am    
Thank you. I've increased the vote.
use Java Script:

Suppose you have button :

JavaScript
$("#btnSubmit").click(function(){

    var vCheckedCBCount =  $("input:checkbox").filter(function(index){ 
    return $(this)[0].checked == true;
    }).length;
    if(vCheckedCBCount > 1)
    {
        alert('You cannot check more than 1 check box.');
        return false;
    } 
});



or try below link....
Allow-to-user-to-check-only-one-checkbox-in-ASPNet-GridView-Row

jquery-to-limit-number-of-checkboxes-user-can-select
 
Share this answer
 
It is used for check only one check box in a column.

VB
Private Sub DataGridView1_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles DataGridView1.CellBeginEdit
        Dim i As Integer = 0
        While (i <> Me.DataGridView1.Rows.Count)
            Me.DataGridView1.Item(e.ColumnIndex, i).Value = False
            i = i + 1
        End While
    End Sub



It is used to check only one check box in a row

VB
Private Sub DataGridView1_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles DataGridView1.CellBeginEdit
       Dim i As Integer = 0
       While (i <> Me.DataGridView1.Columns.Count)
           Me.DataGridView1.Item(i, e.RowIndex).Value = False
           i = i + 1
       End While
   End Sub
 
Share this answer
 
v2

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