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

Setting combobox selectedindex

P: n/a
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
Jul 1 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a

"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:uW**************@TK2MSFTNGP02.phx.gbl...
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.

Jul 1 '07 #2

P: n/a
Because the 0 item is a valid item its the frist item inthe list.

I want nothing selected when I set to -1
"Mr. Arnold" <MR. Ar****@Arnold.comwrote in message
news:ek**************@TK2MSFTNGP04.phx.gbl...
>
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:uW**************@TK2MSFTNGP02.phx.gbl...
>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.

Jul 1 '07 #3

P: n/a
On Sun, 01 Jul 2007 08:23:55 +0200, Rotsey <ma***********@RemoveThis.optusnet.com.auwrote:
Because the 0 item is a valid item its the frist item inthe list.

I want nothing selected when I set to -1
"Mr. Arnold" <MR. Ar****@Arnold.comwrote in message
news:ek**************@TK2MSFTNGP04.phx.gbl...
>>
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:uW**************@TK2MSFTNGP02.phx.gbl...
>>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.

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.

--
Happy coding!
Morten Wennevik [C# MVP]
Jul 1 '07 #4

P: n/a
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

"Morten Wennevik [C# MVP]" <Mo************@hotmail.comwrote in message
news:op.tury0gjzdj93y5@stone...
On Sun, 01 Jul 2007 08:23:55 +0200, Rotsey
<ma***********@RemoveThis.optusnet.com.auwrote:
>Because the 0 item is a valid item its the frist item inthe list.

I want nothing selected when I set to -1
"Mr. Arnold" <MR. Ar****@Arnold.comwrote in message
news:ek**************@TK2MSFTNGP04.phx.gbl...
>>>
"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:uW**************@TK2MSFTNGP02.phx.gbl...
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.


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.

--
Happy coding!
Morten Wennevik [C# MVP]

Jul 1 '07 #5

P: n/a

"Rotsey" <ma***********@RemoveThis.optusnet.com.auwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
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?

Jul 1 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.