[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() { ...
随机推荐
- Xamarin for Visual Studio 3.11.590 稳定版 破解补丁 Version 3
前提概要 全新安装请参考 安装 Xamarin for Visual Studio. Release Log 3.11.590 此版本是紧急修复(HotFix)版,重点改善了 build-tool 及 ...
- [BZOJ1455]罗马游戏 左偏树+并查集
1455: 罗马游戏 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 2285 Solved: 994[Submit][Status][Discuss] ...
- 数学【P2524】 Uim的情人节礼物·其之弐 (康托展开)
因为某人@ZAGER挖坑让我讲一下康托展开,所以发现了这个题,顺便说一下康托展开是个什么东西 题目概括 给定n与一个数列,要求求出给定数列在n的全排列中的排名(按照字典序从小到大排列) 康托展开 先放 ...
- 洛谷——P2067 Cytus-Holyknight
P2067 Cytus-Holyknight 题目背景 本人最初作 以此纪念伟大的ios.安卓.PSV平台音乐游戏<cytus> 后续将不断更新. -------------Chapter ...
- Find intersection of two sorted arrays
共有三种思路. 哈希表. 将较小的那个数组中的所有元素存在哈希表中.然后依次验证另一个数组中的数字是否有出现过.时间复杂度O(m + n),空间复杂度O(min(m, n)) 二分搜索法 将较小的那个 ...
- [CP1804]最短路
题目大意: 一个$n(n\le10^5)$个点的图,给定一个常数$c$,每对点$i,j$之间有权值为$(i\oplus j)\times c$的边.另有$m(m\le5\times10^5)$条指定权 ...
- [POI2010]Beads
题目大意: 给定一个长度为$n(n\leq200000)$的串$S_{1\sim n}$,选择一个$l$,从$S_1$开始,将$S$分为连续的若干段,使得每一段长度为$l$.令$k$为分出来不同的子串 ...
- iOS isa 浅析
看见一到面试题讲述一下Objective-C中的isa?完全没听说过,打算小研究一下. 参考:http://blog.sina.com.cn/s/blog_7a2ffd5c01010nme.html ...
- C语言的运算符、位操作
+ - * / (加 减 乘 除) > >= < <= (大于 大于等于 小于 小于等于) == != (测试等于 测试不等于) && || ! (逻辑与 逻辑 ...
- 解读TDD的五大误区
所谓TDD简单地说就是以下两个步骤:确保所有的需求都能被照顾到:在代码不断增加和重构的过程中,可以检查所有的功能是否正确.本文我们一起来看下关于TDD的五大误区. TDD(全称Test Driven ...