1

私のプログラムはチェックボックス付きのアイテムを受け取り、請求書のアイテムに存在するシリアル番号に応じて、次のコードで追加した詳細ページのリストビューにある金額リストから 1 を引きます。

アイテム - ローソックス(ピンク)
シリアル番号 - 34-75-860
価格 - 5.89
金額 - 12

上記のように行ではなく列にあることを除いて

Dim items As New ListViewItem
    items = ListView1.Items.Add("Low Socks(Pink)")
    items.SubItems.Add("34-75-860")
    items.SubItems.Add("$5.89")
    items.SubItems.Add("12")

    items = ListView1.Items.Add("Low Socks(Black)")
    items.SubItems.Add("34-75-900")
    items.SubItems.Add("$5.89")
    items.SubItems.Add("25")

    items = ListView1.Items.Add("Low Socks(Red)")
    items.SubItems.Add("34-75-756")
    items.SubItems.Add("$5.89")
    items.SubItems.Add("10")

    items = ListView1.Items.Add("Low Socks(Orange)")
    items.SubItems.Add("34-75-234")
    items.SubItems.Add("$5.89")
    items.SubItems.Add("34")

    items = ListView1.Items.Add("Low Socks(Blue)")
    items.SubItems.Add("34-75-598")
    items.SubItems.Add("$5.89")
    items.SubItems.Add("23")
End Sub

請求書ページの下に、請求書の項目の横にチェックボックスがあります。チェックボックスをクリックすると、金額が1つ減ります。後で行って、注文したアイテムの数に応じて必要な実際の金額に変更します...チェックボックスのコーディングは次のとおりです。

Dim item As ListViewItem
    Dim i As Integer
    Dim count As Integer

    'count the number of items in itemdetails2 listview
    count = ItemDetails2.ListView1.Items.Count - 1

    'loop to read each item in the list
    For i = 1 To count

        If i > count Then Exit For

        item = ItemDetails2.ListView1.Items(i)

        'compare the item to the serial number
        If item.Checked = True Then

            If (item.SubItems(0).Text = "34-75-860") Then
                item.SubItems(2).Text -= 1
            End If

            i = i + 1
            count = count - 1
        End If

    Next

    ItemDetails2.Show()
End Sub

今のところ、何もしていないようです。サブアイテムのインデックスを 0 と 2 ではなく 1 と 3 に変更しようとしましたが、それらはサブアイテムであるため、サブアイテム インデックス 0 とサブアイテム インデックス 2 にする必要があると考えました。それが理にかなっていれば....助けてください。

4

1 に答える 1

2

インデックス作成を掘り下げることなく、文字列を数値のように扱っていることに気付くことができます

item.SubItems(2).Text -= 1

あなたが試すべきとき:

item.SubItems(2).Text -= CStr(CDec(item.SubItems(2).Text) - 1D)

それが役立つことを願っています...

于 2012-04-18T18:31:13.307 に答える