ComboBox SelectedIndex = -1 not working

  • Thread starter Thread starter ScottO
  • Start date Start date
S

ScottO

I would like the user to have to select something in a
System.Windows.Forms.ComboBox.

private void MyForm_Load(object sender, System.EventArgs e)
{
...
comboBox.DataSource = data;
comboBox.SelectedIndex = -1;
...
}

Above code does work.

Any thoughts?
 
I would like the user to have to select something in a
System.Windows.Forms.ComboBox.

private void MyForm_Load(object sender, System.EventArgs e)
{
...
comboBox.DataSource = data;
comboBox.SelectedIndex = -1;
...
}

Above code does work.

Working code? Usually people post here when they have problems with
non-working code. :)

I'm not clear on what the "problem" is. Are you saying you don't want
"-1" to clear the list?
 
Hi Scott,

Instead of
comboBox.SelectedIndex = -1;

try using
comboBox.SelectedItem = null;
 
Everyone,

Thanks for the responses.

It was exactly what you mentioned. SelectedIndexChanged event to fire twice
and code some code behind effecting it.

Welcome me to the world of Component programming and Event Handlers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top