944,111 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 26212
  • VB.NET RSS
Apr 12th, 2007
0

Index was out of range. Must be non-negative and less than the size of the collection

Expand Post »
Index was out of range. Must be non-negative and less than the size of the collection Hi,

I've a form and the form is working fine also. But my problem is
Whenever I closed the form. I'm getting two errors.

1.Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

2.Arithmetic overflow error converting varchar to data type numeric.
The statement has been terminated.


Events are :
Private Sub btnFilClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFilClose.Click, btnBrowClose.Click

'This event is used to close the form

Try
Me.Cursor = Cursors.WaitCursor
Me.Close() ' I'm getting the error on this line
Me.Cursor = Cursors.Default
Catch ex As Exception
Me.Cursor = Cursors.Default
MessageBox.Show(ex.Message)
Finally
Me.Cursor = Cursors.Default
Me.Close()
End Try
End Sub

Private Sub forms_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
'This event will be fired automatically whenever form will be closing

Try
Me.Cursor = Cursors.WaitCursor
If MessageBox.Show("Do you want to close this form", Me.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then

'If user press Yes then Form will be closed
Me.Cursor = Cursors.Default
e.Cancel = False
Else

'If User press No the Form will be not closed
e.Cancel = True
End If
Me.Cursor = Cursors.Default
Catch ex As Exception
Me.Cursor = Cursors.Default
MessageBox.Show(ex.Message)
End Try
End Sub

Please help me

Thanx in advance
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Ashok2007 is offline Offline
1 posts
since Apr 2007
Apr 12th, 2007
0

Re: Index was out of range. Must be non-negative and less than the size of the collection

What is index? Where are you using it? Where are you using varchar to data type numeric? There is something wrong here not in your closing, it looks fine to me.
Reputation Points: 84
Solved Threads: 58
Posting Pro in Training
waynespangler is offline Offline
461 posts
since Dec 2002
Nov 9th, 2010
0
Re: Index was out of range. Must be non-negative and less than the size of the collection
when header is clicked of data-grid it has -1 value in it. so make a check on it that if(i!=-1) then perform the operation else do nothing. Thnx
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mfaisalhayat is offline Offline
3 posts
since May 2010
Nov 9th, 2010
0
Re: Index was out of range. Must be non-negative and less than the size of the collection
Have you tried re-programming the check so it will take a value other than zero?

VB.NET Syntax (Toggle Plain Text)
  1. If blah <> 0 then
  2. ' do something
  3. else
  4. ' do something
  5. end if
Reputation Points: 11
Solved Threads: 10
Junior Poster in Training
JJCollins is offline Offline
67 posts
since Sep 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Reading a complete Colum of a multidimensional array at once
Next Thread in VB.NET Forum Timeline: datagridview panel location





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC