Clearing a ComboBox and ListBox

How can you clear a listbox of all its ticks?

How can you reset the ComboBox to its original value. In my case "<<SELECT VALUE>>"?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

U can use Listbox.Items.remove to remove the items. U can use it in a loop like

for i = 0 to listbox.Items.Count -1
Next i

To reset a combobox use can have a empty value added in the combobox while creating it

combobox.items.Add(" ");
Then when u have to reset a value u can select that index.

combobox.SelectedIndex = 1
instead of loop use
listView1.Items.Clear () to reset any collection

Fahad MukhtarDistinguished EngineerCommented:
'How can you reset the ComboBox to its original value. In my case "<<SELECT VALUE>>"?
ComboBox1.SelectedIndex = 0 'usually the orignal value is the first item in the combobox items collection not the second one

'How can you clear a listbox of all its ticks?

are you trying to clear the items and then reset the ComboBox to its original value??? then use this
ComboBox1.Items.Add("<<SELECT VALUE>>")
ComboBox1.SelectedIndex = 0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

PeterErhardAuthor Commented:
Neither work as I expected:

listView1.Items.Clear removes all the items within the listbox. I want to retain all the items but just remove the selected tickes.

ComboBox1.SelectedIndex = 0 gives me the following error - "Specified argument was out of the range of valid values. Paramater name: '0' is not a valid value for index!"
Mike TomlinsonMiddle School Assistant TeacherCommented:
To clear the selected items in a ListBox use:

    ListBox1.SelectedIndex = -1

PeterErhardAuthor Commented:
I just tried this and it didn't work. The ticks still remain.

I've increased the points to 500!
Mike TomlinsonMiddle School Assistant TeacherCommented:
Worked fine for me.  Are you doing anything special with the ListBox?

PeterErhardAuthor Commented:
Nope - the only thing I'm doing is populating it from the database. When I use your code nothing happens.

    Private Function LoadEthnicGroups()

        Dim Index As Byte
        Dim cmd As SqlCommand = cnn.CreateCommand
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "procLoadEthnicGroupOptions"

        Dim reader As SqlDataReader = cmd.ExecuteReader

        With reader
            While reader.Read
                ListBox_EthnicGroup.Items.Item(Index) = .GetValue(.GetOrdinal("EthnicGroup"))
                Index = Index + 1
            End While
        End With


    End Function

dim i as integer
For i = 0 To CheckedListBox.Items.Count - 1
    CheckedListBox.SetItemChecked(i, False)
Next i

For the ComboBox, if you only want to set the selection, and not clear the box, use Desp's answer
ComboBox.SelectedIndex = 0

To clear and reset, you part 2 of Desp's answer:
ComboBox1.Items.Add("<<SELECT VALUE>>")
ComboBox1.SelectedIndex = 0

Hope this helps,

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PeterErhardAuthor Commented:
Thanks for that - all works :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.