Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. My problem is with the Next button. At the last rows, this message appears : System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index'

My problem is with the Next button. At the last rows, this message appears : System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index'

Scheduled Pinned Locked Moved Visual Basic
cssdatabasehelp
6 Posts 4 Posters 11 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    anis78
    wrote on last edited by
    #1

    Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
    Dim i As Integer = DataGridView1.CurrentRow.Index + 1
    If i < 0 Then i = 0
    DataGridView1.CurrentCell = Me.DataGridView1.Rows(i).Cells(0)
    DataGridView1.Rows(i).Selected = True

    End Sub
    
    L S 2 Replies Last reply
    0
    • A anis78

      Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
      Dim i As Integer = DataGridView1.CurrentRow.Index + 1
      If i < 0 Then i = 0
      DataGridView1.CurrentCell = Me.DataGridView1.Rows(i).Cells(0)
      DataGridView1.Rows(i).Selected = True

      End Sub
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Look at the error message again. It is telling you that the value of your index variable is outside the range of rows in DataGridView1. Most likely because of the line below:

      Dim i As Integer = DataGridView1.CurrentRow.Index + 1

      If you are currently at the last row then "Index + 1" will refer to a row that does not exist.

      A 1 Reply Last reply
      0
      • L Lost User

        Look at the error message again. It is telling you that the value of your index variable is outside the range of rows in DataGridView1. Most likely because of the line below:

        Dim i As Integer = DataGridView1.CurrentRow.Index + 1

        If you are currently at the last row then "Index + 1" will refer to a row that does not exist.

        A Offline
        A Offline
        anis78
        wrote on last edited by
        #3

        How can I fix it?

        L G 2 Replies Last reply
        0
        • A anis78

          How can I fix it?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Check to see whether the value is in range, and not just greater than zero.

          1 Reply Last reply
          0
          • A anis78

            How can I fix it?

            G Offline
            G Offline
            gvidali
            wrote on last edited by
            #5

            Better user experience: * Disable the NEXT button when the cursor is on the last row of the grid * Disable the PREVIOUS button when the cursor is on the first row of the grid

            1 Reply Last reply
            0
            • A anis78

              Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
              Dim i As Integer = DataGridView1.CurrentRow.Index + 1
              If i < 0 Then i = 0
              DataGridView1.CurrentCell = Me.DataGridView1.Rows(i).Cells(0)
              DataGridView1.Rows(i).Selected = True

              End Sub
              
              S Offline
              S Offline
              Sernjijj Kabral
              wrote on last edited by
              #6

              Yes, the litehold, of definitive approaches, does do concurrent programming, when SDLC, was exposition of CsE.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups