将新行添加到数据表的顶部
问题描述:
当我们使用datatable.newrow命令时,新的空行添加到行的底部。但是我希望将newrow添加到datatable的顶部。我该怎么做?
When we use datatable.newrow command, a new empty row added to bottom of rows. However I want newrow to added to top of datatable. How can I make it?
答
您使用NewRow创建具有相同列的行。要真正将其放入数据表,必须要做的
You use the NewRow to create a row with the same columns. To actually get it into the DataTable, you've got to do
myDataTable.Rows.InsertAt(myDataRow, 0);
其中0是要插入索引的位置。
Where 0 is the index you want to insert it at.