【问题标题】:Vb.net how to find value on column on datagridVb.net如何在datagrid中的列上查找值
【发布时间】:2017-01-04 10:06:54
【问题描述】:

我一直在寻找

我的桌子是:

Passenger | Destination  | Status

23        |  Mars        | PWD

我可以在第 3 列找到 PWD 的值,但我无法在第 1 列乘以它,因为第 3 列的值为 PWD。​​p>

这是我查找 PWD 值的代码:

For a As Integer = 0 To DataGridView1.Rows.Count - 1
    If (DataGridView1.Rows(a).Cells(2).Value IsNot DBNull.Value Or Trim(DataGridView1.Rows(a).Cells(2).Value <> Nothing) AndAlso DataGridView1.Rows(a).Cells(2).Value = "PWD") Then
        PWD = PWD + 1
    End If
Next
Dim pwdcount = (From row As DataGridViewRow In DataGridView1.Rows _
                  Where row.Cells("Status").Value = "PWD" And row.Cells("Status").Value IsNot DBNull.Value _
                  Select row.Cells("Status").Value).Count()
label1.text = "The number of PWD is : " & pwdcount

【问题讨论】:

    标签: vb.net datagrid


    【解决方案1】:

    我认为您可能正在尝试找到一个 LINQ 解决方案,这不是我在下面的建议。但我相信这会满足您的要求...

        Dim pwdcount As Integer
    
        For Each oRow As DataGridViewRow In DataGridView1.Rows
            Dim oPassengerCell As DataGridViewCell = oRow.Cells("Passenger")
            Dim oStatusCell As DataGridViewCell = oRow.Cells("Status")
    
            If IsNumeric(oPassengerCell.Value) AndAlso oStatusCell.Value = "PWD" Then
                pwdcount += oPassengerCell.Value
            End If
        Next
    
        Label1.Text = "The number of PWD is : " & pwdcount
    

    【讨论】:

    • 价值总是+1
    • total 应该是 30 但它说 33 因为每列都有 +1 值
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-15
    • 2019-09-30
    • 2020-05-15
    • 2012-05-08
    • 1970-01-01
    相关资源
    最近更新 更多