zoukankan      html  css  js  c++  java
  • 两个ComboBox之间Item的移动

            /// <summary>
            /// 绑定权限列表的数据
            /// </summary>
            /// <param name="roleID">-1则,不获取权限列表的数据</param>
            private void DataBindCB(int roleID)
            {
                DataTable dtbPermission = PermissionDAL.GetList();
                DataTable dtbPermissionList = PermissionListDAL.GetList(roleID);
                if (dealTypeCur == DealType.Edit) permissionListOld = new List<int>();

                foreach (DataRow dr in dtbPermissionList.Rows)
                {
                    if (dealTypeCur == DealType.Edit) permissionListOld.Add(Convert.ToInt32(dr["PermissionID"]));

                    DataRow[] drCur = dtbPermission.Select("PermissionID=" + dr["PermissionID"].ToString());
                    if (drCur.Length > 0)
                    {
                        dtbPermission.Rows.Remove(drCur[0]);
                    }
                }

                cbPermissionUnHas.ValueMember = "PermissionID";
                cbPermissionUnHas.DisplayMember = "Description";
                cbPermissionUnHas.DataSource = dtbPermission;

                cbPermissionHas.ValueMember = "PermissionID";
                cbPermissionHas.DisplayMember = "Description";
                cbPermissionHas.DataSource = dtbPermissionList;
            }

    private void btnAddPermission_Click(object sender, EventArgs e)
            {
                //直接操作数据源,防止出现,设置 DataSource 属性后 无法修改项集合
                if (cbPermissionUnHas.SelectedItem == null) return;
                DataTable dtbcbPermissionHasSource = (DataTable)cbPermissionHas.DataSource;
                DataTable dtbcbPermissionUnHasSource = (DataTable)cbPermissionUnHas.DataSource;
                DataRow[] dr = dtbcbPermissionUnHasSource.Select("PermissionID=" + cbPermissionUnHas.SelectedValue.ToString());
                if (dr.Length > 0)
                {
                    if (dtbcbPermissionHasSource.Rows.Count == 0)//防止因为没有数据源,而出现无法新建合适的行
                    {
                        dtbcbPermissionHasSource.Columns.Add("PermissionID", typeof(int));
                        dtbcbPermissionHasSource.Columns.Add("Description", typeof(string));
                        cbPermissionHas.ValueMember = "PermissionID";//重新绑定数据,避免显示出问题
                        cbPermissionHas.DisplayMember = "Description";
                    }
                    DataRow drNew = dtbcbPermissionHasSource.NewRow();
                    drNew["PermissionID"] = dr[0]["PermissionID"];
                    drNew["Description"] = dr[0]["Description"];
                    dtbcbPermissionUnHasSource.Rows.Remove(dr[0]);
                    dtbcbPermissionHasSource.Rows.Add(drNew);
                }
            }

            private void btnRemovePermission_Click(object sender, EventArgs e)
            {
                if (cbPermissionHas.SelectedItem == null) return;
                DataTable dtbcbPermissionHasSource = (DataTable)cbPermissionHas.DataSource;
                DataTable dtbcbPermissionUnHasSource = (DataTable)cbPermissionUnHas.DataSource;
                DataRow[] dr = dtbcbPermissionHasSource.Select("PermissionID=" + cbPermissionHas.SelectedValue.ToString());
                if (dr.Length > 0)
                {
                    if (dtbcbPermissionUnHasSource.Rows.Count == 0)
                    {
                        dtbcbPermissionHasSource.Columns.Add("PermissionID", typeof(int));
                        dtbcbPermissionUnHasSource.Columns.Add("Description", typeof(string));
                        cbPermissionUnHas.ValueMember = "PermissionID";
                        cbPermissionHas.DisplayMember = "Description";
                    }
                    DataRow drNew = dtbcbPermissionUnHasSource.NewRow();
                    drNew["PermissionID"] = dr[0]["PermissionID"];
                    drNew["Description"] = dr[0]["Description"];
                    dtbcbPermissionHasSource.Rows.Remove(dr[0]);
                    dtbcbPermissionUnHasSource.Rows.Add(drNew);
                }
            }

    作者: 火地晋
    出处: http://yelaiju.cnblogs.com
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    4-STM32+CH395Q(以太网)基本控制篇(自建物联网平台)-安装Web服务器软件Nginx(.Windows系统)
    单片机程序底层BUG问题,及解决方案
    3-STM32+CH395Q(以太网)基本控制篇(自建物联网平台)-编写android连接MQTT服务器程序
    2-STM32+CH395Q(以太网)基本控制篇(自建物联网平台)-移植单片机MQTT包,编写stm32+CH395Q连接MQTT服务器程序
    1-STM32+CH395Q(以太网)基本控制篇(自建物联网平台)-购买云主机,安装MQTT软件(linux系统),测试C# 和 网页web连接MQTT服务器
    1-STM32+CH395Q(以太网)基本控制篇(自建物联网平台)-购买云主机,安装MQTT软件(.Windows系统),测试C# 和 网页web连接MQTT服务器
    springmvc缓存--验证通过
    使用nginx缓存服务器上的静态文件
    使用nginx缓存服务器上的静态文件
    Jenkins+maven+Tomcat+SVN一键自动打包部署应用到服务器
  • 原文地址:https://www.cnblogs.com/yelaiju/p/1807492.html
Copyright © 2011-2022 走看看