VB-如何在datagridview中搜索字母

时间:2014-01-26 18:20:26

标签: vb.net for-loop datagridview

基本上,我想要一个标签来记录在特定列中使用“A”字母的次数。我已经制作了这段代码,但它没有用。我是VB的新手 - 请帮忙。

Private Sub Form1_Load
    Dim agrade As Integer = 0
    For Each rw As DataGridViewRow In dgvNames.Rows
        For i As Integer = 0 To rw.Cells.Count - 1
            If rw.Cells(i).Value = "A" Then
                agrade = +1
                lblA_star.Text = astar
            End If
        Next
    Next
End Sub

1 个答案:

答案 0 :(得分:0)

Dim nCol as Integer = ColumnIndexToScan           ' set this to the col index
Dim aCount As integer = 0

For Each rw As DataGridViewRow In dgvNames.Rows
    'For i As Integer = 0 To rw.Cells.Count - 1
        If rw.Cells(nCol).Text.ToUpper = "A" Then
            aCount  += 1
            lblA_star.Text = astar
        End If
    'Next
Next

不要迭代所有列。该问题询问某个字符是否已被使用(包含)但是如果该列等于该字符则测试该代码