Optellen in listview probleem

Status
Niet open voor verdere reacties.

old Hippy

Gebruiker
Lid geworden
24 mei 2008
Berichten
911
Hallo allemaal

ik heb een probleem bij het optellen van bedragen in een listview.

ik gebruik de volgende code deze werkt goed tot dat er een lege cell in de listview staat.
Dan telt het niet meer op b.v.
1000,00
1000,00

1000,00

blijft 1000,00

maar
1000,00
1000,00
1000,00

Word netjes 3000,00
ook als de laatste kolom leeg is telt het niet op.

Iemand een Idee om mij verder te helpen????

Code:
  Dim PriceIndex As Integer = 0
       For Each xCol As ColumnHeader In ListView1.Columns
            If xCol.Text.ToLower = "BTWVerlegd" Then
                PriceIndex = xCol.Index
                Exit For
            End If
        Next

        Dim Sum As Decimal = 0
        Dim Sum1 As Decimal = 0
        Dim Sum2 As Decimal = 0
        Dim Sum3 As Decimal = 0
        Dim Sum4 As Decimal = 0
        For Each Item As ListViewItem In ListView1.Items
            Sum += (Item.SubItems(PriceIndex).Text.ToString)
            Sum1 += (Item.SubItems(PriceIndex + 1).Text.ToString)
            Sum2 += (Item.SubItems(PriceIndex + 2).Text.ToString)
            Sum3 += (Item.SubItems(PriceIndex + 3).Text.ToString)
            Sum4 += (Item.SubItems(PriceIndex + 4).Text.ToString)
        Next
        TB_Totaal1.Text = FormatCurrency(Sum.ToString(), 2)
        TB_Totaal2.Text = FormatCurrency(Sum1.ToString(), 2)
        TB_Totaal3.Text = FormatCurrency(Sum2.ToString(), 2)
        TB_Totaal4.Text = FormatCurrency(Sum3.ToString(), 2)
        TB_Totaal5.Text = FormatCurrency(Sum4.ToString(), 2)
 
Opgelost door er een nul in te zetten als de textbox leeg is.
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan