472,779 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,779 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 6819

"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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.