I want to cache a DataGridView
row between 'refreshes' i.e. between a Rows.Clear()
and a Columns.Clear()
. However it seems that calling the Clear()
methods does not unbind the data from the DataGridView
instance, An example,
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DataGridViewRow cachedRow = new DataGridViewRow();
private void button1_Click(object sender, EventArgs e)
{
this.dataGridView1.Rows.Clear();
this.dataGridView1.Columns.Clear();
DataGridViewColumn aColumn = new DataGridViewTextBoxColumn();
this.dataGridView1.Columns.Add(aColumn);
this.dataGridView1.Rows.Add(cachedRow);
}
}
This is done on a Form containing a DataGridView
and a Button
. Clicking the button twice gives the "Row provided already belongs to a DataGridView" error.
There has been some discussion online about this that suggests that it may be a bug, however this was around 2004.