[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() { ...
随机推荐
- hdu 5101(思路题)
Select Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- poj 1873(枚举所有的状态+凸包)
The Fortified Forest Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6115 Accepted: 1 ...
- Git用法速成手册
Workspace:工作区 Index / Stage:暂存区 Repository:仓库区(或本地仓库) Remote:远程仓库 一.新建代码库 # 在当前目录新建一个Git代码库 git init ...
- 【原创】SSAS-引用维度与多数据源、多数据源视图引发分区错误
背景: 最近有个项目,有32家分公司,集团总部需要取这个32家分公司数据做分析,由于每个分公司的数据都比较庞大,所以最终方案是每个分公司一个DW,在cube搭建过程中将每个公司数据作为一个分区数据的来 ...
- LINUX学习资源
鸟哥:http://vbird.dic.ksu.edu.tw/linux_basic/0430cron.php#cron 五分钟教程:http://roclinux.cn/?page_id=3759
- (11)oracle触发器
触发器是特殊的存储过程. 每当一个特定的数据操作语句(inster,update,delete)在指定的表上触发时,Oracle自动的地执行触发器中定义的语句序列. create trigger 触发 ...
- js获取屏幕
js获取屏幕(设备)宽高 <script language="javascript"> var h = ""; h += " 网页可见区域 ...
- js实现当前日期显示
写在前面: 在做项目中,经常会用到显示当前日期这个功能,在此,记录下来,方便日后查阅. 由于功能较简单,这里就直接将代码搬上来吧 <%-- Created by IntelliJ IDEA. U ...
- Android学Jni/Ndk 开发记录(一)
治疗拖延症的唯一办法就是:一想起些什么 / 要做些什么就 TM 立马去做! 是的,突然想起我不会 JNI.NDK 开发.解决办法:立马去学! 一:配置 NDK 环境 下载 NDK 写入到配置文件 ...
- [Android Traffic] 使用缓存来避免重复的下载
转载自: http://blog.csdn.net/kesenhoo/article/details/7395817 Redundant Downloads are Redundant[重复下载是冗余 ...