dimanche 2 août 2015

How to change checkbox checked in vb.net

I am new in programming so please sorry for asking a very simple question. i have a form with datagrid view and checkbox. what i want is when change datagridview index it will change checkbox checked state. or if i press arrow down or up checkbox will change depending on cell value. here is my code:

Public Sub cellclick()
    Dim row As DataGridViewRow
    Dim r As Integer = usergrid.CurrentRow.Index
    row = Me.usergrid.Rows(r)
   'the value of the cell("ACCES1") maybe yes or no
    If row.Cells("ACCESS1").Value.ToString = "YES" Then
        CheckBox1.CheckState = CheckState.Checked
        'i also try checkbox1.checked=true
    ElseIf row.Cells("ACCESS1").Value.ToString = "NO" Then
        CheckBox1.CheckState = CheckState.Unchecked
        'i also try checkbox1.checked=false
    End If
End Sub 

Private Sub usergrid_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles usergrid.CellEnter
    cellclick()

End Sub

Thank you in advance for those who will help me..




Aucun commentaire:

Enregistrer un commentaire