[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() { ...
随机推荐
- C#模拟进行压力测试
using System; using System.Diagnostics; using System.IO; using System.Net; using System.Text; using ...
- Codeforces Round #299 (Div. 2) B. Tavas and SaDDas【DFS/*进制思维/位运算/一个数为幸运数,当且仅当它的每一位要么是4,要么是7 ,求小于等于n的幸运数个数】
B. Tavas and SaDDas time limit per test 1 second memory limit per test 256 megabytes input standard ...
- request与response对象.
request与response对象. 1. request代表请求对象 response代表的响应对象. 学习它们我们可以操作http请求与响应. 2.request,response体系结构. 在 ...
- [POI2014]Supercomputer
题目大意: 给定一个$n(n\le10^6)$个结点的有根树,从根结点开始染色.每次可以染和已染色结点相邻的任意$k$个结点.$q(q\le10^6)$组询问,每次给定$k$,问至少需要染几次? 思路 ...
- jsp笔记1(基本原理与语法)
web.xml文件配置管理的范围: 1.配置jsp 2.配置和管理Servlet 3.配置和管理Listener 4.配置和管理Filter 5.配置标签库 6.配置jsp属性 7.配置和管理JAAS ...
- shell 调用 sqlplus
一.最简单的shell里调用sqlplus. $ vi test1.sh #!/bin/bashsqlplus -S /nolog > result.log <<EOFset hea ...
- android intent 跳转
转自:http://blog.sina.com.cn/s/blog_7309444701014u2d.html 一.不需要返回值的跳转 Intent intent=new Intent(); inte ...
- N++ 道ASP.NET面试题
InterviewQuestions-ASP.NET N++ 道ASP.NET面试题 1. 简述 private. protected. public. internal 修饰符的访问权限. 答 . ...
- android Broadcast 总结
1, 生命周期 在android官方文档中,推荐我们在onResume中进行 registerReceiver, 在onPause中进行unRegisterReceiver. 他们给出的理由是: If ...
- sqoop使用记录
sqoop简介 Sqoop是用来实现结构型数据(如关系数据库)和Hadoop之间进行数据迁移的工具.它充分利用了MapReduce的并行特点以批处理的方式加快数据的传输,同时也借助MapReduce实 ...