1

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()
4
  • 1
    What exactly is your question? Commented May 17, 2011 at 14:40
  • is the code above in the click handler for cbCars? Commented May 17, 2011 at 14:46
  • 1
    Why call ToString() on a string? Commented May 17, 2011 at 15:20
  • Prefer String.Empty to "". It makes the code at least cleaner Commented May 17, 2011 at 18:18

2 Answers 2

2

Try

txtCars.Text += strText;

or

txtCars.AppendText(strText);
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.