Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

About DataGridView.Rows.Insert

$
0
0

Hello,everyone.

I want to ask something about DataGridView.Rows.Insert.

In a form there is a datagridview.

When right-click menu of a row in the datagridview,a new row is inserted  before selectd row .

DataGridViewRow dgvNewRow = new DataGridViewRow();dgvNewRow.CreateCells(dgv);dgvNewRow.Cells[0].Value="11"dgDocDataList.Rows.Insert(dgvRow.Index + 1, dgvNewRow);//dgvRow is current selected row....//Here is setting values of other controls in current formdgvNewRow.Selected = true;

when running these codes ,sometimes there is a error:

System.InvalidOperationException: DataGridView You can not change the selected property before this object is added to the control.

From the error, i can see the new row is not  successfully inserted,

but i do not how why.Is everybody has the same error?

thanks.



Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>