两个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://www.cnblogs.com/yelaiju/archive/2010/08/24/1807492.html,如需转载请自行联系原作者

目录
相关文章
|
JSON 数据格式
easyUI 的combobox如何获取除valueField和textField外的三个值
easyUI 的combobox如何获取除valueField和textField外的三个值
|
存储 C++ 开发者
QListWidget和QListView的使用和item点击事件
QListWidget和QListView的使用和item点击事件
ListView Item多布局的实现
ListView这个小节的最后一节,给大家带来的是ListView多布局Item的实现, 何为ListView Item多布局,打个比方,QQ这种聊天列表
123 0
|
Android开发
NavigationView中,动态增加item以及menu
NavigationView中,动态增加item以及menu
368 0
|
索引
Android--listView中的button控件获取item的值
版权声明:本文为博主原创文章,转载请标明出处。 https://blog.csdn.net/chaoyu168/article/details/55253877 在listv...
1220 0
|
前端开发
kendo ui grid选中行事件,获取combobox选择的值
背景:   以前用 telerik ui做的grid现在又要换成kendo ui,不过说句实话kendo ui真的比telerik好多,可以说超级升级改头换面。当然用的mvc的辅助方法,以前的telerik ui 选中行的事件是 .OnRowSelect("SelectRow”) ,换成kendo ui 选中行的事件是   .Events(p=>p.Change("SelectRow")) 实现: kendo ui  grid 选中行的事件是  .Events(p=>p.Change("SelectRow"))  。
1986 0