zoukankan      html  css  js  c++  java
  • winfrom 界面中表格数据修改及刷新(DEV)

    信息管理系统中大部分界面是数据展示及数据修改功能,在实现这些功能时由于程序员习惯不同会出现风格迥异的实现逻辑。

    一下是我在开发充总结出的一些小经验,在这里跟大家一起分享交流。

    下面这段代码是编写的一个公共方法,该方法需要4个参数T mdl 操作的实体对象,ActionType acType操作的类型:添加,删除,修改,

    DevExpress.XtraGrid.GridControl 管理界面使用的gridcontrol,CommonControls.CustomXtraGrid
    管理界面使用gridView1
      private void RefreshData<T>(T mdl, ActionType acType, DevExpress.XtraGrid.GridControl gridControl1, CommonControls.CustomXtraGrid gridView1)
            {
                //声明ColumnView对象
                var columnView = (ColumnView)gridControl1.FocusedView;
                //得到选中的行索引
                int focusedhandle = columnView.FocusedRowHandle;
                var dataSource = gridControl1.DataSource as List<T>;
    
                switch (acType)
                {
                    case ActionType.修改:
                        dataSource[focusedhandle] = mdl;
                        break;
                    case ActionType.添加:
                        dataSource.Insert(0, mdl);
                        break;
                    case ActionType.删除:
                        dataSource.Remove(mdl);
                        break;
                }
                this.gridView1.RefreshData();
            }
    //操作类型枚举   
    enum ActionType
        {
            修改 = 0,
            添加,
            删除,
        }
    

      

  • 相关阅读:
    coding++:SpringBoot-事务注解详解
    coding++:java-自定义签名+拦截器
    linux++:Linux
    coding++:java-全局异常处理
    POJ 2823 双端队列
    POJ 3250 栈
    10进制数字向0~3999的罗马数字的转换
    POJ 1986 LCA
    POJ 1236 强联通分量
    河南工业大学2017校赛题解
  • 原文地址:https://www.cnblogs.com/houzf/p/10308669.html
Copyright © 2011-2022 走看看