我有一个程序,它看起来像这样
我的目标是如果存在某个名称且其值为True或其他为假,我如何将复选框的值设置为true
我有这段代码,但它不能正常工作
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
任何帮助都非常感谢TYSM
答案 0 :(得分:0)
找到我的答案
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