User Tools

Site Tools

prog:csharp:241206-01:index

C#: Insert row in middle of DataGridView (2024-12-06)

Solution

  • grid.Rows.Insert(index, 1);
    var addedRow = grid.Rows[index];
  • This inserts 1 empty templated row at 'index', and then simply accesses row in 'index'. The 2nd line is for accessing the just-now-added row.
  • Can also shorten if you know your wished row values with:
  • grid.Rows.Insert(index, FirstName, LastName, BirthDate, Etc);
  • Just have to make sure it is synced with the columns order in the grid, and it makes the row automatically with these fields.
  • 4 person(s) visited this page until now.

Permalink prog/csharp/241206-01/index.txt · Last modified: 2024/12/06 13:45 by jethro

oeffentlich