我有一个gridview,它将有2行,其中包含一些数据,如下所示
101 111111111 1111111111009270754A094101// My first row data
9000002 1000000020222222236000000000000000000000012000000000000000000000000000000000000000//My 2nd row data
我将添加一些值,以便它应插入这两行之间,并且已存在的第二行应移动到datagrid视图的最后一行.就像那样,如果我添加n个值,那么值应该插入到那些2之间,那个已经存在的那一行应该移到最后一行任何想法请
解决方法:
我用经过测试的代码编辑了这个:
public Form1()
{
InitializeComponent();
//This can be removed before utilizing
dgv.Rows.Add("1", "1", "1");
dgv.Rows.Add("1", "1", "1");
dgv.Rows.Add("bob", "bob", "bob");
dgv.Rows.Add("1", "1", "1");
dgv.Rows.Add("1", "1", "1");
dgv.Rows.Add("1", "1", "1");
//This can be removed before utilizing
int oldrow = 2;
dgv.Rows.Add(itemArray(dgv.Rows[oldrow]));
dgv.Rows.RemoveAt(oldrow);
/*
DataGridViewRow oldRow = dataGridView1.Rows.Add(itemarray(dataGridView1.Rows[1])); dataGridView1.Rows.Remove(oldRow)
*/
}
object[] itemArray(DataGridViewRow Row)
{
int a = Row.DataGridView.ColumnCount - 1;
object[] mOut = new object[a+1];
for (int x = 0;x <= a ; x++)
{
mOut[x] = Row.Cells[x].Value;
}
return mOut;
}
我为所有额外的测试道歉.