Setting combobox selectedindex

R

Rotsey

Hi,

I have a combobox that when I set the SelectedIndex to -1
it sets to 0.

The combobox Items property says there is 20 items in it.

Anyone know why this could be please?

rotsey
 
M

Mr. Arnold

Rotsey said:
Hi,

I have a combobox that when I set the SelectedIndex to -1
it sets to 0.

When you do that, it should set the cbo.text to blank with no entry selected
in the dropdown list.
The combobox Items property says there is 20 items in it.

Yeah, ok that's correct. What's the problem?
Anyone know why this could be please?

What's the problem? You're doing things correctly if you don't want the
first enter in the dropdown list to be displayed with the cbo.Text being
blank or null string.
 
R

Rotsey

Because the 0 item is a valid item its the frist item inthe list.

I want nothing selected when I set to -1
 
M

Morten Wennevik [C# MVP]

Because the 0 item is a valid item its the frist item inthe list.

I want nothing selected when I set to -1

Do you have DataBindings or other pieces of code that may change the SelectedIndex? Setting SelectedIndex to -1 will clear the selection (unless it is a dropdown and the user has written new text). If the SelectedIndex ends up as 0 something else is setting it. It would help if you could show us the code.
 
R

Rotsey

no, no databindings

How can I tell what has set it to 0?

When i debug this I see that the selectedindex has a value say 5
then I try to set to -1 and then it is 0.

Seems to a bug in my code somehow i suppose.

My app reads a xml file and abstracts creatng a data form
from this.
What code would be helpful to see? i could give the project source
i guess, only a few files.

rotsey
 
M

Mr. Arnold

Rotsey said:
no, no databindings

How can I tell what has set it to 0?

When i debug this I see that the selectedindex has a value say 5
then I try to set to -1 and then it is 0.

Seems to a bug in my code somehow i suppose.

My app reads a xml file and abstracts creatng a data form
from this.
What code would be helpful to see? i could give the project source
i guess, only a few files.

You got code in the SelectedIndexChanged event, which is going to firer
every time you manipulate the cbobox, like load it or SelectedIndex -1 is
going to make the event firer and execute code?
 

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

Top