0

我只是编码的初学者,我想以编程方式检查checklistbox使用datagridview.

数据网格视图值用逗号分隔,如下所示jhon,Metilda,saman,

复选框名称为chklistinput,请帮我解决这个问题?

'完整的编码在这里......................

 Private Sub TextBox10_TextChanged(sender As Object, e As EventArgs) Handles TextBox10.TextChanged

'this is ok and searching as I want 

    Dim SearchV As String = TextBox10.Text
    SearchV = "%" + TextBox10.Text + "%"

    Me.PassIssuingRecordTableAdapter.FillBy(Me.Database4DataSet.PassIssuingRecord, SearchV)


'But the problem bigins here 

    Dim areasback As String = DataGridView1.Rows(0).Cells(6).Value.ToString
    Dim areasback1 As String() = areasback.Split(",")

    For Each x In areasback1
        For i = 0 To areasback.Count - 1

            If chklistInput.Items(i).ToString() = x.ToString() Then
                chklistInput.SetItemChecked(i, False)
            End If

        Next
    Next

End Sub
4

1 回答 1

0

你必须循环chklistInput.Items.Count - 1而不是areasback.Count - 1

使用以下代码:

Dim areasback As String = DataGridView1.Rows(0).Cells(6).Value.ToString
Dim areasback1 As String() = areasback.Split(",")
Dim intCount as integer = 0 

For each str as string in areasback1

    For intCount = 0 To chklistInput.Items.Count - 1

        If chklistInput.Items(intCount).ToString() = str Then
            chklistInput.SetItemChecked(intCount , True)
        End If

    Next

Next

chklistInput.Refresh()

注意:比较区分大小写

于 2016-12-05T16:42:13.657 回答