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];//设定当前行

                    }

                }

            }

  • 相关阅读:
    linux 中的./configuration --prefix=安装路径 的用法(指定源码安装方式的安装路基)
    深入了解Activiti工作流流程定义
    ResultCode 自定义错误状态码
    maven和gradle对比
    js中的prototype原型解析
    json字符串的标准格式
    迷茫于Hibernate/JPA的人提一些建议。
    ModelDriven 和 Preparable 拦截器
    Spring中bean的scope
    spring配置文件详解以及beans:beans标签
  • 原文地址:https://www.cnblogs.com/MyBeN/p/3085130.html
Copyright © 2011-2022 走看看