当前位置导航:炫浪网>>网络学院>>编程开发>>Visual C#教程

实现DataGridView中行的上下移动

        1)        如果dgOutImage.DataSource=集合(RecFileArgs)

        (向上移动)

        dgOutImage.DataSource = new BindingList<RecFileArgs>(RecFileArgs1);
        //如果选择的是多行
        if (dgOutImage.SelectedRows.Count > 1)
         {
             return;
         }
         dgOutImage.Focus();
        //目前选择的行号
           int rowIndex = dgOutImage.CurrentRow.Index;
                if (rowIndex != 0)
                {
               RecFileArgs _reccCurr = dvrPlayListRight[rowIndex];
               RecFileArgs _reccPer = dvrPlayListRight[rowIndex - 1];
               dvrPlayListRight[rowIndex] = _reccPer;
               dvrPlayListRight[rowIndex - 1] = _reccCurr;
               dgOutImage.DataSource = dvrPlayListRight;
               dgOutImage.Refresh();
               dgOutImage.Rows[rowIndex - 1].Selected = true;
               dgOutImage.CurrentCell = dgOutImage.Rows[rowIndex - 1].Cells[0];
               }
        if (rowIndex - 1 == 0)
               {
                   向上按钮.Enabled = false;
               }
               else
               {
                   向上按钮.Enabled = true;
           }

        2)        如果dgOutImage.DataSource= DataTable

        (向下移动)

        object[] _rowData   =   DataTable.Rows[i].ItemArray;

        DataTable.Rows[i].ItemArray   =   DataTable.Rows[i+1].ItemArray

        DataTable.Rows[i+1].ItemArray   =   _rowData;

相关内容
赞助商链接