I have a datatable with one column:
我有一个包含一列的数据表:
this.callsTable.Columns.Add("Call", typeof(String));
I then want to add a row to that datatable, but want to give a specific index, the commented number is the desired index:
然后我想在该数据表中添加一行,但是想要给出一个特定的索引,注释的数字是所需的索引:
this.callsTable.Rows.Add("Legs"); //11
Update:
- Must be able to handle inputting hundreds of rows with unique indexes.
- The index must be what is defined by me no matter if there are enough rows in the table or not for the insertat function.
必须能够处理输入具有唯一索引的数百行。
无论表中是否有足够的行用于insertat函数,索引必须是我定义的。
1 个解决方案
#1
14
You can use DataTable.Rows.InsertAt
method.
您可以使用DataTable.Rows.InsertAt方法。
DataRow dr = callsTable.NewRow(); //Create New Row
dr["Call"] = "Legs"; // Set Column Value
callsTable.Rows.InsertAt(dr, 11); // InsertAt specified position
See: DataRowCollection.InsertAt Method
请参阅:DataRowCollection.InsertAt方法
If the value specified for the pos parameter is greater than the number of rows in the collection, the new row is added to the end.
如果为pos参数指定的值大于集合中的行数,则新行将添加到结尾。
#1
14
You can use DataTable.Rows.InsertAt
method.
您可以使用DataTable.Rows.InsertAt方法。
DataRow dr = callsTable.NewRow(); //Create New Row
dr["Call"] = "Legs"; // Set Column Value
callsTable.Rows.InsertAt(dr, 11); // InsertAt specified position
See: DataRowCollection.InsertAt Method
请参阅:DataRowCollection.InsertAt方法
If the value specified for the pos parameter is greater than the number of rows in the collection, the new row is added to the end.
如果为pos参数指定的值大于集合中的行数,则新行将添加到结尾。