How can I manually add data to a dataGridView?

前端 未结 5 635
梦谈多话
梦谈多话 2020-12-16 19:23

I\'m trying to run this code, and I get an exception:

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

5条回答
  •  醉话见心
    2020-12-16 20:06

    There are 0 cells in the newly created row, that's why you are getting that exception. You cannot use statements like

    row.Cells[0].Value = i.ToString();
    

    unless you manually add cells to the blank row.

提交回复
热议问题