473,394 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 6872

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Shravan | last post by:
Hi, In my code sometimes the combox.selectedindex = <intIndex> doesn't set the combo selectedindex, when I checked the items in the combo the count is greater than <intIndex> Can anybody help...
2
by: ross kerr | last post by:
Hi all, I have a control that extends the ComboBox object. It updates the selected item based on what the user enters in the text area. In the OnLeave event of the combobox, the selected...
3
by: ScottO | last post by:
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;...
1
by: mike | last post by:
Hi, I'd like advice from a .NETer. I have a loadcombo routine which sets the selectedindex to -1 if it's an "add record", but then it goes to a security routine which, based on permissions...
4
by: Strahimir Antoljak | last post by:
Has anyone experienced problems with a combo box SelectIndex property? Is there a limit to the number of Items for a combo box? Namely, when I set programmatically ComboBox.SelectIndex...
9
by: Atchoum | last post by:
I have a combobox populated with objects from a class derived from FileInfo. When I try to assign a value to selected index, I get a "Argument length must be greater of equal to 0". What is this...
1
by: Carl Tribble | last post by:
I want to set the value in the combo box so that it displays no text in the visible portion and it returns a value of -1 for SelectedIndex. I have been using: ComboBoxName.SelectedIndex = -1 ...
5
by: john.halet | last post by:
This line of code had been working with out issue, now its throwing errors. In my case I have three items in the ComboBox. If I try to change the selected index it throw the error. Earler in...
3
by: Magnus | last post by:
Im using a set combobox (ComboBox1) to provide a selection of records from a database table. I have a typed dataset (DataSet1) that contains the typed datatable (DataTable1) that the combobox is...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.