Problems with combobox selectedindex

  • Thread starter Thread starter Atchoum
  • Start date Start date
A

Atchoum

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.
 
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.
 
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 said:
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.
 
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.
 
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...
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top