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

                    }

                }

            }

  • 相关阅读:
    windows2016优化
    oracle什么时候需要commit
    Mysql的锁表,锁行记录
    git add
    linux系统优化
    解决rsyslog启动问题
    HAProxy启用日志功能
    nc命令获取远端端口状态
    将pip源更换到国内镜像
    Centos7.6下安装Python3.7
  • 原文地址:https://www.cnblogs.com/MyBeN/p/3085130.html
Copyright © 2011-2022 走看看