bolo
bolo

Reputation: 21

Issue with checkbox and textbox

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
    Next
    txtCars.Text = strText.ToString()

Upvotes: 1

Views: 390

Answers (2)

Bala R
Bala R

Reputation: 109027

Try

txtCars.Text += strText;

or

txtCars.AppendText(strText);

Upvotes: 2

Michael Pryor
Michael Pryor

Reputation: 25356

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.

Upvotes: 0

Related Questions