开发者

Issue with checkbox and textbox

开发者 https://www.devze.com 2023-03-06 07:08 出处:网络
I\'m having a little issue with my code not displaying correctly. Right now if there\'s text in the textbox and I select something from the checkbox list, what I selected from the checkboxlist overrid

I'm having a little issue with my code not displaying correctly. Right now if there's text in the textbox and I select something from the checkbox list, what I selected from the checkboxlist overrides what's in the textbox. I want to keep what's in the textbox and just keep adding on what's selected.

For example: Honda's in the textbox ... I select Dodge and Mazda I want to show Honda, Dodge, Mazda

Dim i As Integer = 0
    Dim strText As String = ""

    For i = 0 To cbCars.Items.Count - 1
        If cbCars.Items(i).Selected Then
            If strText = "" Or strTeethText = Nothing Then
                strText += cbTeeth.Items(i).Text 
            Else
                strText += ", " & cbCars.Items(i).Text
            End If
        End If
 开发者_Python百科   Next
    txtCars.Text = strText.ToString()


Try

txtCars.Text += strText;

or

txtCars.AppendText(strText);


Change

Dim strText As String = ""

to

Dim strText As String = txtCars.Text

You forgot to initialize your string to the value of the textbox, which is why the textbox was getting overwritten on your click handler.

0

精彩评论

暂无评论...
验证码 换一张
取 消