Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

When I load my form, I can set the combobox to show a blank line by writing

 

cbo1.SelectedIndex = -1

 

But when I need to re-initialize it to blank later, that same code doesn't work.

 

Why not? And how can I set it to nothing again? I also tried

 

cbo1.SelectedItem = Nothing

Posted

That doesn't work - I get the error message:

Cannot modify the Items collection when the DataSource property is set.

 

I have my controls bound to the data at design time,rather than in code. Do I need to unbind and rebind in the code?

  • *Experts*
Posted

Change the dropdown style before you set the index to -1 and you'll get an empty combobox that is editible.

 

cmbEmployeeName.DropDownStyle = ComboBoxStyle.DropDown
cmbEmployeeName.SelectedIndex = -1

 

Jon

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...