By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,237 Members | 1,332 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,237 IT Pros & Developers. It's quick & easy.

Cannot set SelectedIndex to -1 in ComboBox

P: n/a
Hi,

I've narrowed down a problem I've been having filling a combobox with the
results of a query stored in a datatable. I'm setting the ValueMember and
DisplayMember to the relevant column names, and then I want to make sure
nothing is selected.

By default it appears that if you do nothing, the first item (0) is
selected. However, I want to set the SelectedIndex to -1.

If I have a standalone window it works, but if I have a window that has an
mdiparent set, it ignores my attempts to set the SelectedIndex to -1 and
always selects item 0.

(here's my code...)
ComboBox1.DataSource = dt
ComboBox1.ValueMember = "chCountryCode"
ComboBox1.DisplayMember = "chCountryDesc"
ComboBox1.SelectedIndex = -1

I've already tried setting SelectedIndex = -1 twice, but that doesn't fix
it. The only thing that seems to fix it is making the window non-childmdi,
but our application is an MDI style app!

Is this a bug? Any ideas please?

Many thanks,

Steve
Nov 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.