Edmondo
Edmondo

Reputation: 20080

Inserting an empty row in DataGridView

I want to introduce a graphical separation between group of rows in a DataGridView.

Which are the options I have: - Should I introduce an empty row? - Should I work with borders and/or the paint methods ?

Upvotes: 3

Views: 5942

Answers (4)

T30
T30

Reputation: 12222

This increases the lower border of the row at specified [Index]:

DataGridViewRow row = dataGridView1.Rows[Index];
row.DividerHeight = 1;

Note that DividerHeigth uses the space of the row, so if you set it to 10 it can cover half row (for me, 1 is enough).

There is also DividerWidth property to separate groups of columns.

Upvotes: 7

Sasidharan
Sasidharan

Reputation: 3740

DataGridViewRow DGVR= (DataGridViewRow)yourDataGridView.Rows[0].Clone();
DGVR.Cells[0].Value = "XYZ";
DGVR.Cells[1].Value = 50.2;
yourDataGridView.Rows.Add(DGVR);

Upvotes: 0

Tobia Zambon
Tobia Zambon

Reputation: 7629

With the Rows.Add() method you add a new row, you can obtain a reference to it by using:

var newRow = dg.Rows[dg.Rows.Add()];

So you can manipulate your new row after, example:

newRow.Cells["myColumn"].Value = "asd";

Upvotes: 0

Dhaval
Dhaval

Reputation: 2861

grid.Rows.Insert(index, 1);
var addedRow = grid.Rows[index];

This inserts 1 empty templated row at 'index'.

Upvotes: 1

Related Questions