簡體   English   中英

將項目添加到列表

[英]Adding Item to a List

我正在嘗試獲取用戶輸入的字符串並將其傳輸到列表中。 當我單擊添加按鈕時,列表會清除。 這是代碼。 謝謝你的幫助

Const ModelPrompt As String = "Input Car Model"
Const ModelTitle As String = "Car Model"

Const PricePrompt As String = "Input Car MSRP"
Const PriceTitle As String = "Car MSRP"


carModel = InputBox(ModelPrompt, ModelTitle)
carPrice = InputBox(PricePrompt, PriceTitle)

Do While carModel <> String.Empty _
AndAlso carPrice <> String.Empty

    carListBox.Items.Add(carModel)
    msrpListBox.Items.Add(carPrice)

Loop

這是我朋友的代碼

    Const ModelPrompt As String = "Input Car Model"
    Const ModelTitle As String = "Car Model"

    Const PricePrompt As String = "Input Car MSRP"
    Const PriceTitle As String = "Car MSRP"

    Dim carModel As Object = InputBox(ModelPrompt, ModelTitle)
    Dim carPrice As Object = InputBox(PricePrompt, PriceTitle)

    If String.IsNullOrEmpty(carModel) = False And String.IsNullOrEmpty(carPrice) = False Then
        ListBox1.Items.Add(carModel)
        ListBox2.Items.Add(carPrice)
    End If

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM