DataGridView列仅显示值0

时间:2015-11-19 10:47:56

标签: vb.net

我从未遇到过datagridview对象的这种奇怪行为。 填充到此列的m populating a column from a dataset to a datagridview column. all the columns are presented properly except one column, all the string i显示为" 0" 但是细胞的实际价值不是" 0"它应该在那里的字符串(通过循环列并使用messegebox显示值来检查) 我无法弄清楚如何解决这个问题。

代码:

Private Sub filldgv(ByVal dgv As DataGridView, ByVal colarr() As String, ByVal query As String, ByVal table As String)
        dgv.Rows.Clear()
        Dim ds As DataSet
        Dim fill As New Analist.SalesAnalistArray
        ds = fill.ReturenDataSet(query, table)

        If ds.Tables(table).Rows.Count >= 1 Then
            ' add rows
            If ds.Tables(table).Rows.Count > 1 Then
                dgv.Rows.Add(ds.Tables(table).Rows.Count - 1)
            End If


            ' populate to dgv
            For i = 0 To ds.Tables(table).Rows.Count - 1
                For Each itm In colarr
                    dgv.Rows(i).Cells(itm.Substring(0, itm.IndexOf("|").ToString)).Value = ds.Tables(table).Rows(i).Item(itm.Substring(itm.IndexOf("|") + 1, (itm.Length - itm.IndexOf("|")) - 1).ToString).ToString
                Next
            Next
        End If


        ' calculate income of each Account Manager
        ds.Clear()
        ds = fill.ReturenDataSet("SELECT G, F, K, L, M, N FROM Calculator", "Calculator")
        table1 = ds.Tables("Calculator")



        For i = 0 To dgv.Rows.Count - 1
            'totalIncome = dt.Compute("Sum(K)", "G= " & dgv.Rows(i).Cells(0).ToString)

            dgv.Rows(i).Cells(3).Value = getIncome(dgv.Rows(i).Cells(0).Value, dgv.Rows(i).Cells(1).Value)
        Next


        table1.Dispose()
        fill.Dispose()
        ds.Dispose()
        ds = Nothing
        table1 = Nothing
    End Sub

1 个答案:

答案 0 :(得分:0)

确定令人尴尬......在我删除这篇文章之前,这个“如果有人”解决了它。有问题的专栏是第3栏......

   If dgv.Name = "dgvAcManagers" Then


            ds = fill.ReturenDataSet("SELECT G, F, K, L, M, N FROM Calculator", "Calculator")
            table1 = ds.Tables("Calculator")



            For i = 0 To dgv.Rows.Count - 1
                'totalIncome = dt.Compute("Sum(K)", "G= " & dgv.Rows(i).Cells(0).ToString)

                dgv.Rows(i).Cells(3).Value = getIncome(dgv.Rows(i).Cells(0).Value, dgv.Rows(i).Cells(1).Value)
            Next


            table1.Dispose()
        End If