473,624 Members | 2,117 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6887

"Rotsey" <ma***********@ RemoveThis.optu snet.com.auwrot e in message
news:uW******** ******@TK2MSFTN GP02.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.c omwrote in message
news:ek******** ******@TK2MSFTN GP04.phx.gbl...
>
"Rotsey" <ma***********@ RemoveThis.optu snet.com.auwrot e in message
news:uW******** ******@TK2MSFTN GP02.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.optu snet.com.auwrot e:
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.c omwrote in message
news:ek******** ******@TK2MSFTN GP04.phx.gbl...
>>
"Rotsey" <ma***********@ RemoveThis.optu snet.com.auwrot e in message
news:uW******* *******@TK2MSFT NGP02.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.comwro te in message
news:op.tury0gj zdj93y5@stone.. .
On Sun, 01 Jul 2007 08:23:55 +0200, Rotsey
<ma***********@ RemoveThis.optu snet.com.auwrot e:
>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.c omwrote in message
news:ek******* *******@TK2MSFT NGP04.phx.gbl.. .
>>>
"Rotsey" <ma***********@ RemoveThis.optu snet.com.auwrot e in message
news:uW****** ********@TK2MSF TNGP02.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.optu snet.com.auwrot e in message
news:%2******** ********@TK2MSF TNGP04.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 SelectedIndexCh anged 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
1218
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 me why is it not setting the index. I bound a dataview to Combo, whose items change dynamically, after the list of items in the view are
2
4523
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 index is set to the proper item. However, when accessing its selectedindex later it has reverted to the previous value. The selectedindex value is always one behind what
3
16214
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; comboBox.SelectedIndex = -1; ... }
1
2403
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 sets the visible property. When the visible property is set.. 'Petition Type lblPetitionType.Visible = False
4
2608
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 property with 2000 Items listed in the ComboBox, SelectIndex property accepts assigned value. However, when I try to use SelectIndex
9
4639
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 about? For i = 0 To cboCalc.Items.Count - 1 Dim Item As FileInfoExt Item = cboCalc.Items(i) If Item.TruncatedFileName = DefaultName Then cboCalc.SelectedIndex = i Exit For
1
1595
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 But this does not always work (sometimes, the selected index after executing this line of code is actually 0 and therefore, of course, the first item in the list is displayed.
5
3098
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 the code I check to see if the combobox has any items, if so then I set it to 0 with out issue. Then a bit later in the code I try to set it to the last server used.
3
6712
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 bound to. The datatable in the dataset is filled using the typed tableadapter (TableAdapter1). DataTable consists of the typical primary key and value fields. Here is the designer generated code for ComboBox1: this.ComboBox1.DataSource =...
0
8238
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8174
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8680
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8478
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6111
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2607
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1485
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.