Click here to Skip to main content
15,667,466 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can you guys help me? When I double click the cell row in datagridview to edit the information, the error shows it says that :

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

ACC_REG is the name of the windowform where they can their information. I'm using VB.NET and MS ACCESS DATABASE


I hope you can help me. Please do respect my question, Thankyou.

What I have tried:

Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
       With ACC_REG
           .storeCode.Text = DataGridView1.CurrentRow.Cells(0).Value
           .usr1.Text = DataGridView1.CurrentRow.Cells(1).Value
           .password1.Text = DataGridView1.CurrentRow.Cells(2).Value
           .storeName.Text = DataGridView1.CurrentRow.Cells(3).Value

           Dim bytes As [Byte]() = DataGridView1.CurrentRow.Cells(4).Value
           Dim ms As New MemoryStream(bytes)
           .PictureBox1.Image = Image.FromStream(ms)
           .addbtn.Enabled = False
           .storeCode.ReadOnly = True
           .ShowDialog()


       End With
   End Sub
Posted
Updated 7-Nov-22 2:28am

1 solution

You didn't tell us which line the error occurs on, but the error message suggests that the CurrentRow doesn't have at least five cells.

You'll need to debug your code and step through the method to find out how many cells it does have. Then work out why it doesn't have as many cells as you expect.

We can't do that for you, since we have no access to your computer.
 
Share this answer
 
Comments
Hazel Ann Torno 2022 7-Nov-22 10:02am    
HI! THIS LINE ERROR OCCURS 'Dim bytes As [Byte]() = DataGridView1.CurrentRow.Cells(4).Value' Can you tell me what's wrong with that?
Richard Deeming 7-Nov-22 10:04am    
As I said, the CurrentRow doesn't contain at least five cells. If the error occurs when you try to access .Cells(4), then it only contains four cells, with indexes from 0 to 3.

You need to debug your code to find out why. We can't do that for you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900