Question How to clear selected item in combo box with clear button?

amiradilah

New member
Joined
Nov 3, 2014
Messages
1
Programming Experience
Beginner
Private Sub ButtonClearData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonClearData.Click
ComboBox1.SelectedItem.Clear()
ComboBox2.SelectedItem.Clear()
ComboBox3.SelectedItem.Clear()
ComboBox4.SelectedItem.Clear()
ComboBox5.SelectedItem.Clear()
ComboBox6.SelectedItem.Clear()
ComboBox7.SelectedItem.Clear()

This is my coding but it doesn't work at all! so how can i clear the selected item of combo box with the clear button?
please help me.
this is urgent!

thanks.
 
That code doesn't make sense. The SelectedItem property of the ComboBox returns the item that is selected. Let's say that you have added Strings to the ComboBox. In that case, the SelectedItem is a String. What exactly do you think will happen if you call Clear on a String? Given that the String class doesn't even have a Clear method, nothing good.

Think about the state of the ComboBox if no item is selected. The SelectedIndex will be -1 and the SelectedItem will be Nothing. It works both ways. You simply set one of those properties to that value and there will be no item selected.
 

Latest posts

Back
Top