Is it possible to show row number in the row header of a DataGridView
?
I\'m trying with this code, but it doesn\'t work:
pri
row.HeaderCell.Value = row.Index + 1;
when applied on datagridview with a very large number of rows creates a memory leak and eventually will result in an out of memory issue. Any ideas how to reclaim the memory?
Here is sample code to apply to an empty grid with some columns. it simply adds rows and numbers the index. Repeat button click a few times.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
dataGridView1.SuspendLayout();
for (int i = 1; i < 10000; i++)
{
dataGridView1.Rows.Add(i);
}
dataGridView1.ResumeLayout();
}
private void button1_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
row.HeaderCell.Value = (row.Index + 1).ToString();
}
}