When I try to add a new row to a DataGridView in virtual mode like this:
dataGridViewX1.Rows.Add(new string[] { "Parker", "Seattle" });
The following exception occurs:
Operation is not valid when the DataGridView control is in virtual mode?
When I try to add a new row to a DataGridView in virtual mode like this:
dataGridViewX1.Rows.Add(new string[] { "Parker", "Seattle" });
The following exception occurs:
Operation is not valid when the DataGridView control is in virtual mode?
When a DataGridView
is in Virtual mode (DataGridView.VirtualMode = true
), that means that the DataGridView
's content is supplied from a source other than itself through events exposed on the DataGridView
. If you intend for your DataGridView to be in virtual mode, you need to add the new information to the underlying source and then tell the DataGridView
that there is another row, like this:
// add information to the underlying source
this.dataGridView.RowCount++;
If you did not intend to use DataGridView
in virtual mode, you can turn off virtual mode by setting DataGridView.VirtualMode
to false
.
You need to use data source to add new row and it will show in DataGridView automatically.