Ado - Driving me Nuts

  • Thread starter Thread starter MadCrazyNewbie
  • Start date Start date
M

MadCrazyNewbie

Hey Group,

I keep getting the following Error and its driving me nuts now.

"An unhandled exception of type 'System.IndexOutOfRangeException' occurred
in system.data.dll
Additional information: There is no row at position 1."

it keeps erroring on this line:
Private Sub dsPasswordlist_PositionChanged()
If Me.BindingContext(dsPasswordList, "PasswordList").Position <> -1 Then
Me.cboPasswordListsDepartment.SelectedValue =
dsPasswordList.PasswordList.Rows(Me.BindingContext(dsPasswordList,
"PasswordList").Position).Item("DepartmentID")
End If
End Sub

Anybody got any Ideas?

Many Thanks
Si
 
You know what? I'm getting exactly the same exception, intermittantly, on
one of my list boxes. What I've done to "get around" it is to wrap the
statement in a try...catch so that it doesn't happen at runtime. Its
totally weird and, I think, a bug (at least I hope it is). For me, it
doesn't matter too much if the operation fails. For you, I don't know.
 
Hey Robin,

What would be the best way to use Try and Catch in this senario?

Regards
MCN
 
Hi Mad,

When that Private sub ds.... is called, because that we cannot see.

In this case you can even put that dump try and catch block around it
because there is nothing really that could be catched. It would only be a
much more time consuming method than just set a flag around it when it is,
as I asume, in the initialization fase of the dataset or combobox.

Cor
 
Well first of all, you need to de-obfuscate your code, something like this:

Private Sub dsPasswordlist_PositionChanged()

Dim thePosition as integer = BindingContext ( dsPasswordList,
"PasswordList" ).Position

If thePosition <> -1 Then

try

cboPasswordListsDepartment.SelectedValue =
dsPasswordList.PasswordList.Rows(thePosition).Item ("DepartmentID")

catch ex as Exception

' Take appropriate alternative action here.

End Try

End If

End Sub

If you look at my problem here, you can see how illogical the exception is.
I am even guarding the access with a check! I mean I say if the count of
selectedindices is one, then get me the zeroth (first) item. Still, very
occassionally, it raises the indexoutofrange exception.

Try
If ListBox.SelectedIndices.Count = 1 Then

' will occassionally get an "indexoutofrangeexception' if you use
' SelectedIndex property. So I use SelectedIndices(0) here instead,
' which seems to hold the correct value, but still can cause the
exception.
' This will have to be looked further into at some point.

If ListBox.SelectedIndices(0) >= 0 Then
Return ListBox.SelectedIndices(0)
End If
End If

Catch Ex As IndexOutOfRangeException

End Try
 
Back
Top