第一行  No.1  No.2  No.3  No.4  No.5 
第二行  张三  李四   王五    钱六   孙七 
第三行  29    25    26     27    28 
第四行 北京市 天津市 上海市  广州市 哈尔滨市 
第五行 0001  0002  0003   0004   0005 现在的问题是:我想交换第二列和第三列的数据,该怎么写?
 是否可以交换任意两列的数据?

解决方案 »

  1.   

    dim n as datagrid.rown=datagrid.rows(1)
    datagrid.rows(1)=datagrid.rows(2)
    datagrid.rows(2)=nn=nothing
      

  2.   

    不好意思.看错了.以为是交换行数据.交换列吗?是datagrid控件还是数据库里.如果是数据为里,最好是用proc来做.
    还要用到游标.
    关于游标,可以查询sql的帮助文件.
      

  3.   


        this.dataGridView1.Columns[2].DisplayIndex = this.dataGridView1.Columns[2].Index + 1;
      

  4.   


    如果是datagrid里.用循环吧.和交换两个变量没啥区别.
      

  5.   

    在datatabile里修改。注意新建一个row,然后就像更改变量一样,a=b,b=c,c=a,
      

  6.   

                  try
                {                this.dataGridView1.Columns[1].DisplayIndex = this.dataGridView1.Columns[1].Index + 1;
                }
                catch
                {
                    this.dataGridView1.Columns[1].DisplayIndex  = 0;
                }
      

  7.   

     foreach (DataGridViewRow row in this.dataGridView1.Rows)
                {
                    temp = Convert.ToString(row.Cells[3].Value);
                    row.Cells[3].Value = row.Cells[2].Value;
                    row.Cells[2].Value = temp;
                }
      

  8.   

     foreach (DataGridViewRow row in this.dataGridView1.Rows)
                {
                    temp = Convert.ToString(row.Cells[3].Value);
                    row.Cells[3].Value = row.Cells[2].Value;
                    row.Cells[2].Value = temp;
                }
      

  9.   


               try
                {                this.dataGridView1.Columns[1].DisplayIndex = this.dataGridView1.Columns[1].DisplayIndex + 1;
                }
                catch
                {
                    this.dataGridView1.Columns[1].DisplayIndex  = 0;
                }
      

  10.   

    其实很简单啊:如果你是2005 的话:dtTotal.Columns[j].SetOrdinal(11);自己研究