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

Problems with combobox selectedindex

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

TIA.
Nov 21 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
It means that your cboCalc.Items collection has zero items in it, so your i
variable gets assigned -1, so it then tries to assign -1 to the
SelectedIndex - which it can't as it has to be zero or above.

Hope this helps.

Matt.

"Atchoum" <goglus@DONT_SPAM_ME_videotron.ca> wrote in message
news:kv*****************@weber.videotron.net...
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
End If
Next

TIA.

Nov 21 '05 #2

P: n/a
Yes, I think your right. But the OP seems to inisit the ListBox is
populated.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Matt S" <ma**@toomuchspamalready.com> wrote in message
news:uN**************@TK2MSFTNGP11.phx.gbl...
It means that your cboCalc.Items collection has zero items in it, so your i variable gets assigned -1, so it then tries to assign -1 to the
SelectedIndex - which it can't as it has to be zero or above.

Hope this helps.

Matt.

"Atchoum" <goglus@DONT_SPAM_ME_videotron.ca> wrote in message
news:kv*****************@weber.videotron.net...
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
End If
Next

TIA.


Nov 21 '05 #3

P: n/a
* "Matt S" <ma**@toomuchspamalready.com> scripsit:
It means that your cboCalc.Items collection has zero items in it, so your i
variable gets assigned -1, so it then tries to assign -1 to the
SelectedIndex - which it can't as it has to be zero or above.


'SelectedIndex' /can/ take the value -1.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #4

P: n/a
If count was zero, how could it even enter the loop?

Steve

"Matt S" <ma**@toomuchspamalready.com> wrote in message
news:uN**************@TK2MSFTNGP11.phx.gbl...
It means that your cboCalc.Items collection has zero items in it, so your i variable gets assigned -1, so it then tries to assign -1 to the
SelectedIndex - which it can't as it has to be zero or above.

Hope this helps.

Matt.

"Atchoum" <goglus@DONT_SPAM_ME_videotron.ca> wrote in message
news:kv*****************@weber.videotron.net...
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
End If
Next

TIA.


Nov 21 '05 #5

P: n/a
It does have items in it. As steve said, it would not enter the loop.

Atchoum
Nov 21 '05 #6

P: n/a
You're right, Steve. It does have items.

Atchoum
Nov 21 '05 #7

P: n/a
Argument length is probably referring to the length of a string, not the
value of 0. Is your DefaultName a null string, i.e., = to ""? If so, the
error might be generated by trying to set Item.TruncatedFileName equal to a 0
length string.

"Atchoum" wrote:
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
End If
Next

TIA.

Nov 21 '05 #8

P: n/a
Thank you all for responding. Forget it. I am stupid. There was an error in
the selectedindex event which was triggering this message.
I wonder though when I am going step by step with VB.NET why sometimes it
does not go to the next sub or function. For example, in this case, if I
step into the code, when it assigns the selectedindex value, why am I not
taken to the SelectedIndex event when using "step into"? Instead it just
stays there and returns the error without a chance of knowing really which
line is the culprit. It was not doing this in vb6...
Nov 21 '05 #9

P: n/a
Atchoum,

The selectedindex event fires forever when the combobox is loaded, it even
gives in some situation in my idea unpredictable results.

Most of us protect that by setting a switch in that event to be sure that it
is only be used when the combobox is completlly loaded.

I hope this helps?

Cor
Nov 21 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.