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
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    AtomQQ 随笔
    android下服务器推送实现 androidpn分析
    Pyqt Model/view框架 5.排序与过滤
    微软官方windows phone开发视频教程第二天视频(附下载地址)
    微软官方windows phone开发视频教程第一天视频(附下载地址)
    微软官方windows phone开发视频教程第三/四天视频(附下载地址)
    初见Ajax——javascript访问DOM的三种访问方式
    一个经历,实习?兼职?
    SQL分割字符串详解
    asp.net服务器控件button先执行js再执行后台的方法
  • 原文地址:https://www.cnblogs.com/yelaiju/p/1807492.html
Copyright © 2011-2022 走看看