Clear ComboBox Items "VbExpress 2005"  
Author Message
Shady9399





PostPosted: Visual Basic Express Edition, Clear ComboBox Items "VbExpress 2005" Top

Hi

How Can I clear ComboBox collection clicking on the button

My ComboBox contain some values from DataBase and I have tried this code

ComboBox1.Items.Clear()

but display this error  "Items collection cannot be modified when the DataSource property is set."

Someone can help to resolve this problem

Thanks


Shady

 




Visual Studio Express Editions2  
 
 
DMan1





PostPosted: Visual Basic Express Edition, Clear ComboBox Items "VbExpress 2005" Top

You combobix is bound to a datasource, which means to edit the contents of the combobox you must edit the contents of the datasource and then refresh....your other option is to remove the databinding completely and then clear

 
 
Shady9399





PostPosted: Visual Basic Express Edition, Clear ComboBox Items "VbExpress 2005" Top

I want to refresh.

But when i refresh that add the existing collection again.

For example: In my combobox I have "Test1" and "Test2", when I'm clickng on refresh button that will add "Test1"and "Test2" again. I would like to clear the comboBox Collection and then add the dataBase values.



 
 
spotty





PostPosted: Visual Basic Express Edition, Clear ComboBox Items "VbExpress 2005" Top

Have you checked that Clearbeforefill property

http://msdn2.microsoft.com/en-us/library/bz9tthwx.aspx

If this is not set correctly then each time you refresh its like you appending the same records over again resulting in duplicates in the dataset rather than a refreshing them.