zoukankan      html  css  js  c++  java
  • DataGridView上下移动行及设置当前行

    //方法 上移 下移 删除 dGVshowProcess是一个DataGridView

            private void upOrdownOrDelete(string type)

            {           

                if (this.dGVshowProcess.CurrentRow == null)

                {

                    MessageBox.Show("请选择要需要操作的工序所在行");

                }

                else if(type=="del")//删

                {

                    if (MessageBox.Show("确定要删除吗?", "警告", MessageBoxButtons.YesNo) == DialogResult.Yes)

                    {

                        this.dGVshowProcess.Rows.Remove(this.dGVshowProcess.CurrentRow);

                    }

                }

                else if(type=="up")//上

                {

                    if (this.dGVshowProcess.CurrentRow.Index <= 0)

                    {

                        MessageBox.Show("此工序已在顶端,不能再上移!");

                    }

                    else

                    {                                 

                        int nowIndex = this.dGVshowProcess.CurrentRow.Index;

                        object[] _rowData = (this.dGVshowProcess.DataSource as DataTable).Rows[nowIndex].ItemArray;

                        (this.dGVshowProcess.DataSource as DataTable).Rows[nowIndex].ItemArray = (this.dGVshowProcess.DataSource as DataTable).Rows[nowIndex - 1].ItemArray;

                        (this.dGVshowProcess.DataSource as DataTable).Rows[nowIndex-1].ItemArray = _rowData;                  

                        this.dGVshowProcess.CurrentCell = this.dGVshowProcess.Rows[nowIndex - 1].Cells[0];//设定当前行

                    }

                }

                else if (type == "down")//下

                {

                    if (this.dGVshowProcess.CurrentRow.Index >= this.dGVshowProcess.Rows.Count-1)

                    {

                        MessageBox.Show("此工序已在底端,不能再下移!");

                    }

                    else

                    {                  

                        int nowIndex = this.dGVshowProcess.CurrentRow.Index;

                        object[] _rowData = (this.dGVshowProcess.DataSource as DataTable).Rows[nowIndex].ItemArray;

                        (this.dGVshowProcess.DataSource as DataTable).Rows[nowIndex].ItemArray = (this.dGVshowProcess.DataSource as DataTable).Rows[nowIndex + 1].ItemArray;

                        (this.dGVshowProcess.DataSource as DataTable).Rows[nowIndex+1].ItemArray = _rowData;

                        this.dGVshowProcess.CurrentCell = this.dGVshowProcess.Rows[nowIndex + 1].Cells[0];//设定当前行

                    }

                }

            }

  • 相关阅读:
    Kafka 1.0.0集群安装
    java实现以docx格式导出
    基于java处理.docx格式的word合并
    基于java 合并.doc和docx格式的Word文件
    Docker版本Jenkins的使用
    Codeforces 1243 D 0-1 MST
    Public model for matrix
    Codeforces 1220 E Tourism
    Codeforces 1221 G Graph And Numbers
    Codeforces 1221 F Choose a Square
  • 原文地址:https://www.cnblogs.com/MyBeN/p/3085130.html
Copyright © 2011-2022 走看看