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

后端 未结 5 1746
挽巷
挽巷 2020-12-10 01:03

I\'m trying to add data as one by one row to a datagridview here is my code and it says:

\"Index was out of range. Must be non-negative and less than

5条回答
  •  -上瘾入骨i
    2020-12-10 01:41

    what this means ? is there any problem in my code

    It means that you are accessing a location or index which is not present in collection.

    To find this, Make sure your Gridview has 5 columns as you are using it's 5th column by this line

    dataGridView1.Columns[4].Name = "Amount";
    

    Here is the image which shows the elements of an array. So if your gridview has less column then the (index + 1) by which you are accessing it, then this exception arises.

    enter image description here

提交回复
热议问题