简体   繁体   中英

Set checkbox value to true if Data in Datagridview exist else False

I have a program and it looks like this

在此处输入图片说明

My Target here is how can I set the value of the checkbox to true if a certain Name exist and its value = True or else false

I have this code but its not working

    For Each dr As DataGridViewRow In Me.DataGridView1.Rows
                If dr.Cells(0).Value.ToString = "Button2" and dr.Cells(1).Value.ToString = "True" Then checkbox23.checked = True Else checkbox23.checked = False

and so on
.
.
.
.
.
.
.
.
.
.
.
            Next
        End Sub

any help is well appreciated TYSM

Found my answer

  Public Function EnableByPermission(ByVal buttonName As String) As Boolean
        Dim Enable As Boolean = False

        ' Look over the Enumerable collection of Rows the one where the
        ' cell for ControlName contains the button name required
        Dim row = DataGridView1.Rows _
                  .Cast(Of DataGridViewRow)() _
                  .FirstOrDefault(Function(x) _
                      x.Cells("ControlName").Value.ToString = buttonName)


        ' If we found it then return the boolean value for the Access column      
        If row IsNot Nothing Then
            Enable = Convert.ToBoolean(row.Cells("Access").Value)
        End If
        Return Enable
    End Function
    Private Sub Form7_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        CheckBox23.Checked = EnableByPermission("Button2")
    End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM