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
"MadCrazyNewbie" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hey Robin,
>
> What would be the best way to use Try and Catch in this senario?
>
> Regards
> MCN
>
> "Robin Tucker" <(E-Mail Removed)> wrote in
> message news:c3sf40$a40$1$(E-Mail Removed)...
> > 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.
> >
> > "MadCrazyNewbie" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > 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
> > >
> > >
> >
> >
>
>
|