Pasting excel data into a blank DataGridView - Index out of range exception

前端 未结 8 1490
不思量自难忘°
不思量自难忘° 2020-12-30 07:20

I have an excel sheet with the following:

\"enter

So, what I am trying to achi

8条回答
  •  离开以前
    2020-12-30 08:01

    A really nice solution was posted here:

    But, one line needs to be changed:

     if (dgv.Rows.Count < (r + rowsInClipboard.Length))
                dgv.Rows.Add(r + rowsInClipboard.Length - dgv.Rows.Count);
    

    needs to be changed to:

     if (dgv.Rows.Count < (r + rowsInClipboard.Length))
                dgv.Rows.Add(r + rowsInClipboard.Length+1 - dgv.Rows.Count);
    

    If this line isn't changes, the last row pasted will not be passed to SQL.

提交回复
热议问题