简体   繁体   English

如何使用datagridview vb.net检查清单框项目?

[英]how to check checklistbox items using datagridview vb.net?

I'm just a beginner for coding and I want to programmatically check items in checklistbox using datagridview . 我只是编码的初学者,我想使用datagridview以编程方式检查checklistbox datagridview项目。

Data grid view values are seperated with commas like this jhon,Metilda,saman, . 数据网格视图值用逗号分隔,例如jhon,Metilda,saman,

Checklistbox name as chklistinput and please help me to solve this ? chklistinput名称为chklistinput ,请帮助我解决此问题?

'Full coding is here.............................. ``完整的编码在这里.....................

 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

You have to loop over chklistInput.Items.Count - 1 instead of areasback.Count - 1 您必须遍历chklistInput.Items.Count - 1而不是areasback.Count - 1

use the following code: 使用以下代码:

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()

Note: comparing is case sensitive 注意:比较区分大小写

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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