/// <summary>
/// 点击节点前,可以不使用
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void treeList1_BeforeCheckNode(object sender, DevExpress.XtraTreeList.CheckNodeEventArgs e)
{
e.State = (e.PrevState == CheckState.Checked ? CheckState.Unchecked : CheckState.Checked);
}
/// <summary>
/// 点击节点后
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void treeList1_AfterCheckNode(object sender, DevExpress.XtraTreeList.NodeEventArgs e)
{
SetCheckedChildNodes(e.Node, e.Node.CheckState);
SetCheckedParentNodes(e.Node, e.Node.CheckState);
}
/// <summary>
/// 选择子节点时触发
/// </summary>
/
// <param name="node"></param>
/// <param name="check"></param>
private void SetCheckedChildNodes(TreeListNode node, CheckState check)
{
for (int i = 0; i < node.Nodes.Count; i++)
{
node.Nodes[i].CheckState = check;
SetCheckedChildNodes(node.Nodes[i], check);
}
}
/// <summary>
/
// 选择父节点时触发
/// </summary>
/// <param name="node"></param>
/// <param name="check"></param>
private void SetCheckedParentNodes(TreeListNode node, CheckState check)
{
if (node.ParentNode != null)
{
bool b = false;
CheckState state;
for (int i = 0; i < node.ParentNode.Nodes.Count; i++)
{
state = (CheckState)node.ParentNode.Nodes[i].CheckState;
if (!check.Equals(state))
{
b = !b;
break;
}
}
node.ParentNode.CheckState = b ? CheckState.Indeterminate : check;
SetCheckedParentNodes(node.ParentNode, check);
}
}
/// <summary>
/// 判断此节点下的所有子节点是否选中
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
private Boolean IsChildsChecked(TreeListNode node)
{
for (int i = 0; i < node.Nodes.Count; i++)
{
if (node.Nodes[i].CheckState == CheckState.Unchecked)
return false;
if (node.Nodes[i].HasChildren)
IsChildsChecked(node.Nodes[i]);
}
return true;
}
private void GetCheckedID(TreeListNode parentNode)
{
if (parentNode.Nodes.Count == 0)
return;//递归终止
foreach (TreeListNode node in parentNode.Nodes)
{
if (node.CheckState == CheckState.Checked)
{
DataRow dr = treeList_JPBW.GetDataRecordByNode(node) as DataRow;//关键代码
string a=dr[0].ToString();
//if (drv != null)
//{
// int GroupID= (int)drv["GroupID"];
// //lstCheckedOfficeID.Add(GroupID);
//}
}
}
}
private List<string> treeList_CheckCount = new List<string>();//选择节点ID的集合
/// <summary>
/// 获取选择状态的数据主键ID集合
param name/// </summary>
/// <param name="parentNode">父级节点 root</param>
private void GetCheckedID(TreeListNode parentNode)
{
if (parentNode.Nodes.Count == 0)
{
return;//递归终止
}
foreach (TreeListNode node in parentNode.Nodes)
{
if (node.CheckState == CheckState.Checked)
{
DataRowView dr = treeList_JPBW.GetDataRecordByNode(node) as DataRowView;//关键代码
if (dr != null)
{
string ID = dr["ID"].ToString();
treeList_CheckCount.Add(ID);
}
}
GetCheckedID(node);
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论