i have a checked list box as one of my controls in my code what happens is when i click on the checked list box the item clicked in the checked list box is supposed to be added to a text box, and my code is now doing that however when a user clicks an item item and then unclicks it it becomes a problem.pliz help the code is below.

If txtSQL.Text = "" Then
            txtSQL.Text = chlTableCols.GetItemText(chlTableCols.SelectedItem.ToString)
        Else
            txtSQL.Text = txtSQL.Text.ToString + ("," + chlTableCols.GetItemText(chlTableCols.SelectedItem))
        End If

Recommended Answers

All 2 Replies

Hi!

Try this:

If txtSQL.Text = "" Then
            txtSQL.Text = chlTableCols.GetItemText(chlTableCols.SelectedItem.ToString)
        Else
            If Not (txtSQL.Text.Contains(chlTableCols.SelectedItem.ToString)) Then
                txtSQL.Text = txtSQL.Text & "," & chlTableCols.GetItemText(chlTableCols.SelectedItem)
            Else
                txtSQL.Text = "," & txtSQL.Text
                txtSQL.Text = txtSQL.Text.Replace("," & chlTableCols.GetItemText(chlTableCols.SelectedItem), "")
                txtSQL.Text = txtSQL.Text.TrimStart(",")
            End If
        End If

great dude, the code works well. thanx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.