第一行 No.1 No.2 No.3 No.4 No.5
第二行 张三 李四 王五 钱六 孙七
第三行 29 25 26 27 28
第四行 北京市 天津市 上海市 广州市 哈尔滨市
第五行 0001 0002 0003 0004 0005 现在的问题是:我想交换第二列和第三列的数据,该怎么写?
是否可以交换任意两列的数据?
第二行 张三 李四 王五 钱六 孙七
第三行 29 25 26 27 28
第四行 北京市 天津市 上海市 广州市 哈尔滨市
第五行 0001 0002 0003 0004 0005 现在的问题是:我想交换第二列和第三列的数据,该怎么写?
是否可以交换任意两列的数据?
datagrid.rows(1)=datagrid.rows(2)
datagrid.rows(2)=nn=nothing
还要用到游标.
关于游标,可以查询sql的帮助文件.
this.dataGridView1.Columns[2].DisplayIndex = this.dataGridView1.Columns[2].Index + 1;
如果是datagrid里.用循环吧.和交换两个变量没啥区别.
{ this.dataGridView1.Columns[1].DisplayIndex = this.dataGridView1.Columns[1].Index + 1;
}
catch
{
this.dataGridView1.Columns[1].DisplayIndex = 0;
}
{
temp = Convert.ToString(row.Cells[3].Value);
row.Cells[3].Value = row.Cells[2].Value;
row.Cells[2].Value = temp;
}
{
temp = Convert.ToString(row.Cells[3].Value);
row.Cells[3].Value = row.Cells[2].Value;
row.Cells[2].Value = temp;
}
try
{ this.dataGridView1.Columns[1].DisplayIndex = this.dataGridView1.Columns[1].DisplayIndex + 1;
}
catch
{
this.dataGridView1.Columns[1].DisplayIndex = 0;
}