471,319 Members | 1,649 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

Setting combobox selectedindex

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
5 6714

"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
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
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
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

"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.

Similar topics

reply views Thread by Shravan | last post: by
3 posts views Thread by ScottO | last post: by
4 posts views Thread by Strahimir Antoljak | last post: by
9 posts views Thread by Atchoum | last post: by
1 post views Thread by Carl Tribble | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.