check box in data grid

rahcue

New member
Joined
Jul 9, 2010
Messages
1
Programming Experience
Beginner
Hi,
I am using the datagrid in order to show a list of data. The data grid is made up of a number of columns of which one of them is tickbox coloumn. I have also one button to transfer the data. Therefore if the user wants to transfer the data, he just check the checkbox and click transfer. Now the problem is that when there is no check in the checkboxes I want the button transfer to be viewed but disabled. Any suggestion how i can do it ??
 
In CellValueChanged event for relevant e.ColumnIndex you can loop all rows and see if any checkbox is checked (Value=True) and set buttons Enabled property accordingly. For example:
VB.NET:
If e.ColumnIndex = 0 Then
    Dim enable As Boolean
    For Each row As DataGridViewRow In Me.DataGridView1.Rows
        enable = enable Or CBool(row.Cells(e.ColumnIndex).Value)               
    Next
    Me.Button1.Enabled = enable
End If
Note, when you say 'datagrid' I interpret it as DataGridView control, which is what you should be using with .Net 2.0 onwards.
 
Back
Top