[DevExpress]TreeListLookUpEdit带checkbox之经典运用
上代码:
public partial class TreeListLookUpEdit : DevExpress.XtraEditors.XtraForm
{ private string _KeyName;
public string KeyName
{
get { return lblKeyName.Text; }
set { lblKeyName.Text = value; }
}
private string _KeyID; public string KeyID
{
get { return lblKeyID.Text; }
set { lblKeyID.Text= value; }
}
public TreeListLookUpEdit()
{
InitializeComponent();
}
private void TreeListLookUpEdit_Load(object sender, EventArgs e)
{
} protected override void OnLoad(EventArgs e)
{
base.OnLoad(e); if (DesignMode) return;
txtRole.Properties.TreeList.OptionsView.ShowCheckBoxes = true;
txtRoleBind();
DefaultChecked("3");
GetSelectedRoleIDandName(); txtRole.Properties.TreeList.AfterCheckNode += (s, a) =>
{
a.Node.Selected = true;
// txtRole.RefreshEditValue();
// txtRole.ForceClosePopup();
GetSelectedRoleIDandName();
}; }
private void GetSelectedRoleIDandName()
{
this.lstCheckedKeyID.Clear();
this.lstCheckedKeyName.Clear(); if (txtRole.Properties.TreeList.Nodes.Count > 0)
{
foreach (TreeListNode root in txtRole.Properties.TreeList.Nodes)
{
GetCheckedKeyID(root);
}
}
lblKeyID.Text = "";
lblKeyName.Text = "";
foreach (int id in lstCheckedKeyID)
{
KeyID += id + ",";
} foreach (string name in lstCheckedKeyName)
{
KeyName += name + ",";
}
}
private void DefaultChecked(string rid)
{
string strSql = " SELECT [MID] FROM [DZ].[dbo].[DZ_RoleMenu] where RID=" + rid;
DataTable dt = DbHelperSQL.Query(strSql).Tables[0]; if (txtRole.Properties.TreeList.Nodes.Count > 0)
{
foreach (TreeListNode nd in txtRole.Properties.TreeList.Nodes)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
int checkedkeyid = int.Parse(dt.Rows[i][0].ToString());
if (txtRole.Properties.TreeList.FindNodeByKeyID(checkedkeyid) != null)
{
txtRole.Properties.TreeList.FindNodeByKeyID(checkedkeyid).Checked = true;
}
}
}
} }
private void txtRoleBind()
{
DZAMS.BLL.DZ_RoleInfo rf = new BLL.DZ_RoleInfo();
string where = "1=1 order by PARENTID,ID ASC";
DataTable tblDatas = rf.GetList(where).Tables[0]; //设置字段
this.txtRole.Properties.TreeList.KeyFieldName = "ID";
this.txtRole.Properties.TreeList.ParentFieldName = "PARENTID";
this.txtRole.Properties.DataSource = tblDatas; this.txtRole.Properties.ValueMember = "ID";
this.txtRole.Properties.DisplayMember = "NAME";
}
private List<int> lstCheckedKeyID = new List<int>();//选择局ID集合
private List<string> lstCheckedKeyName = new List<string>();//选择局Name集合
/// <summary>
/// 获取选择状态的数据主键ID集合
/// </summary>
/// <param name="parentNode">父级节点</param>
private void GetCheckedKeyID(TreeListNode parentNode)
{
if (parentNode.Nodes.Count == 0)
{
return;//递归终止
}
if (parentNode.CheckState != CheckState.Unchecked)
{
DataRowView drv = txtRole.Properties.TreeList.GetDataRecordByNode(parentNode) as DataRowView;
if (drv != null)
{
int KeyFieldName = (int)drv["ID"];
string DisplayMember = drv["NAME"].ToString();
if (!lstCheckedKeyID.Contains(KeyFieldName))
{
lstCheckedKeyID.Add(KeyFieldName);
}
if (!lstCheckedKeyName.Contains(DisplayMember))
{
lstCheckedKeyName.Add(DisplayMember);
}
}
}
foreach (TreeListNode node in parentNode.Nodes)
{
if (node.CheckState != CheckState.Unchecked)
{
DataRowView drv = txtRole.Properties.TreeList.GetDataRecordByNode(node) as DataRowView;//关键代码,就是不知道是这样获取数据而纠结了非常久(鬼知道能够转换为DataRowView啊)
if (drv != null)
{
int KeyFieldName = (int)drv["ID"];
string DisplayMember = drv["Name"].ToString();
lstCheckedKeyID.Add(KeyFieldName);
lstCheckedKeyName.Add(DisplayMember);
}
}
GetCheckedKeyID(node);
} } private void txtRole_Closed(object sender, DevExpress.XtraEditors.Controls.ClosedEventArgs e)
{
} void txtRole_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
{
e.DisplayText = lblKeyName.Text;
}
}
[DevExpress]TreeListLookUpEdit带checkbox之经典运用的更多相关文章
- WPF中Expander控件样式,ListBox的样式(带checkbox)恢复
Expander控件样式: <ControlTemplate x:Key="ExpanderToggleButton" TargetType="ToggleButt ...
- WPF 带CheckBox、图标的TreeView
WPF 带CheckBox.图标的TreeView 在WPF实际项目开发的时候,经常会用到带CheckBox的TreeView,虽然微软在WPF的TreeView中没有提供该功能,但是微软在WPF中提 ...
- 【转】带checkbox的ListView实现(二)——自定义Checkable控件的实现方法
原文网址:http://blog.csdn.net/harvic880925/article/details/40475367 前言:前一篇文章给大家展示了传统的Listview的写法,但有的时候我们 ...
- WPF 带CheckBox、图标的TreeView(转)
在WPF实际项目开发的时候,经常会用到带CheckBox的TreeView,虽然微软在WPF的TreeView中没有提供该功能,但是微软在WPF中提供强大的ItemTemplate模板功能和自定义样式 ...
- Silverlight TreeView 带 checkbox和图片
前段时间做Silverlight TreeView 控件,但是要带checkbox和图片,在网上到处找相关的例子,效果图如下 xaml代码 <UserControl x:Class=" ...
- Flex带CheckBox的Tree(修改ItemRenderer)
此文代码参考了:http://summerofthatyear-gmail-com.iteye.com/blog/326302 在此表示感谢! 前文提到了,实现带CheckBox的Tree有两种方法: ...
- 带CheckBox美化控件的表格全选
带CheckBox美化控件 <table class="positionTable commonListTable" id="positionTable" ...
- DevExpress Grid使用checkBox选中的方法
到官网得到消息自13.2版本后的Dev Grid中均内置了CheckBox列多选功能.在寻找答案的过程的成果进行记录. 一.13.2版本以后用法 启用多选列 对Gird中的View进行以下属性设置: ...
- Devexpress GridView增加CheckBox列
参考DEV官网代码做了一个增加checkbox列效果: #region 方法:设置GridView数据绑定 public void GridDataBind() { ...
随机推荐
- python tips;matplotlib 显示中文
import numpy as npimport matplotlib.pyplot as pltimport matplotlib as mpl mpl.rcParams['axes.unicode ...
- 【原创】Oracle 11g R2 Client安装配置说明(多图详解)
1. 准备工作 安装Oracle11gR2client的时候,如果刚从网上下载的Oracle client,可能无法再2008 R2或者2012 R2的服务器上面运行. 报错:[INS-13001]环 ...
- [BZOJ1997][Hnoi2010]Planar 2-sat (联通分量) 平面图
1997: [Hnoi2010]Planar Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 2317 Solved: 850[Submit][Stat ...
- UVA 437 巴比伦塔 【DAG上DP/LIS变形】
[链接]:https://cn.vjudge.net/problem/UVA-437 [题意]:给你n个立方体,让你以长宽为底,一个个搭起来(下面的立方体的长和宽必须大于上面的长和宽)求能得到的最长高 ...
- The expression being assigned to optional parameter `v2' must be a constant or default value
今天写代码的时候遇到一个问题以前没有遇到过的问题,就是当我给一个对象参数赋值默认值的时候,报错了,代码如下 public void ShowOrHiddenKuang(bool isShow,Vect ...
- 细说JavaScript对象(4): for in 循环
如同 in 运算符一样,使用 for in 循环遍历对象属性时,也将往上遍历整个原型链. // Poisoning Object.prototype Object.prototype.bar = 1; ...
- linux命令详解:cat命令
转:http://www.cnblogs.com/lwgdream/archive/2013/11/06/3409802.html 前言 cat命令用于读取文本文件,并且能够显示行号.特殊字符等. 使 ...
- Oracle多用户对一个表进行并发插入数据行操作
oracle数据库支持多用户间同时对同一个表进行操作,但是数据不一定同步,因为oracle数据库是支持脏数据的,比如A用户删除了表的数据但没有提交,B用户也能查询访问到,如果要避免这种情况只能加锁,A ...
- jquery验证表单代码
代码如下: //开始验证-修改用户密码 $('.editUserPwd').validate({ /**//* 设置验证规则 */ rules: { lname:{ required:true, st ...
- linux下小试redis demo
先启动 redis-server /etc/redis/redis.conf package com.test; import java.util.ArrayList; import java.ut ...