C# 遍历当前选中节点的子节点
答案:4 悬赏:80 手机版
解决时间 2021-03-19 18:09
- 提问者网友:我们很暧昧
- 2021-03-19 07:06
C# 遍历当前选中节点的子节点
最佳答案
- 五星知识达人网友:玩家
- 2021-03-19 08:02
#region ===获取指定节点下已选择的值===
///
/// 获取指定节点下已选择的值
///
///
///
public static string GetSelectedChildNodeVText(TreeNode Node)
{
string StrChecked = "";
foreach (TreeNode nd in Node.ChildNodes)
{
if (nd.Checked)
{
StrChecked += nd.Text + ",";
}
if (nd.ChildNodes.Count > 0)
{
StrChecked += GetSelectedChildNodeVText(nd);
}
}
StrChecked = StrChecked.TrimStart(',');
return StrChecked;
}
#endregion
#region===获取指定节点下已选择的文本内容===
///
/// 获取指定节点下已选择的文本内容
///
///
///
public static string GetSelectedChildNodeVValue(TreeNode Nodes)
{
string StrCheckedValue = "";
foreach (TreeNode nd in Nodes.ChildNodes)
{
if (nd.Checked)
{
StrCheckedValue += nd.Value + ",";
}
if (nd.ChildNodes.Count > 0)
{
StrCheckedValue += GetSelectedChildNodeVValue(nd);
}
}
StrCheckedValue = StrCheckedValue.TrimStart(',');
return StrCheckedValue;
}
#endregion
///
/// 获取指定节点下已选择的值
///
///
///
public static string GetSelectedChildNodeVText(TreeNode Node)
{
string StrChecked = "";
foreach (TreeNode nd in Node.ChildNodes)
{
if (nd.Checked)
{
StrChecked += nd.Text + ",";
}
if (nd.ChildNodes.Count > 0)
{
StrChecked += GetSelectedChildNodeVText(nd);
}
}
StrChecked = StrChecked.TrimStart(',');
return StrChecked;
}
#endregion
#region===获取指定节点下已选择的文本内容===
///
/// 获取指定节点下已选择的文本内容
///
///
///
public static string GetSelectedChildNodeVValue(TreeNode Nodes)
{
string StrCheckedValue = "";
foreach (TreeNode nd in Nodes.ChildNodes)
{
if (nd.Checked)
{
StrCheckedValue += nd.Value + ",";
}
if (nd.ChildNodes.Count > 0)
{
StrCheckedValue += GetSelectedChildNodeVValue(nd);
}
}
StrCheckedValue = StrCheckedValue.TrimStart(',');
return StrCheckedValue;
}
#endregion
全部回答
- 1楼网友:胯下狙击手
- 2021-03-19 10:47
this.treeView1.SelectedNode.Nodes[]数组。
- 2楼网友:往事隔山水
- 2021-03-19 09:37
这个肯定是要用递归的!!
//在树和树的节点下面递归去找,看有没有等于该ID的节点,有的话就选中
private void getnodes(TreeNode node, string id)
{
//NODE为空的话就直接在树下面找
if (node == null)
{
foreach (TreeNode nodeaa in treeDepts.Nodes)
{
if (nodeaa.Value == id)
{
nodeaa.Checked = true;
break;
}
foreach (TreeNode item in nodeaa.ChildNodes)
{
getnodes(item, id);
}
}
}
//不为空就在传进来的节点下面找
else
{
if (node.Value == id)
{
node.Checked = true;
}
foreach (TreeNode item in node.ChildNodes)
{
getnodes(item, id);
}
}
}
//在树和树的节点下面递归去找,看有没有等于该ID的节点,有的话就选中
private void getnodes(TreeNode node, string id)
{
//NODE为空的话就直接在树下面找
if (node == null)
{
foreach (TreeNode nodeaa in treeDepts.Nodes)
{
if (nodeaa.Value == id)
{
nodeaa.Checked = true;
break;
}
foreach (TreeNode item in nodeaa.ChildNodes)
{
getnodes(item, id);
}
}
}
//不为空就在传进来的节点下面找
else
{
if (node.Value == id)
{
node.Checked = true;
}
foreach (TreeNode item in node.ChildNodes)
{
getnodes(item, id);
}
}
}
- 3楼网友:举杯邀酒敬孤独
- 2021-03-19 08:19
#region ===获取指定节点下已选择的值===
///
/// 获取指定节点下已选择的值
///
///
///
public static string GetSelectedChildNodeVText(TreeNode Node)
{
string StrChecked = "";
foreach (TreeNode nd in Node.ChildNodes)
{
if (nd.Checked)
{
StrChecked += nd.Text + ",";
}
if (nd.ChildNodes.Count > 0)
{
StrChecked += GetSelectedChildNodeVText(nd);
}
}
StrChecked = StrChecked.TrimStart(',');
return StrChecked;
}
#endregion
#region===获取指定节点下已选择的文本内容===
///
/// 获取指定节点下已选择的文本内容
///
///
///
public static string GetSelectedChildNodeVValue(TreeNode Nodes)
{
string StrCheckedValue = "";
foreach (TreeNode nd in Nodes.ChildNodes)
{
if (nd.Checked)
{
StrCheckedValue += nd.Value + ",";
}
if (nd.ChildNodes.Count > 0)
{
StrCheckedValue += GetSelectedChildNodeVValue(nd);
}
}
StrCheckedValue = StrCheckedValue.TrimStart(',');
return StrCheckedValue;
}
#endregion
///
/// 获取指定节点下已选择的值
///
///
///
public static string GetSelectedChildNodeVText(TreeNode Node)
{
string StrChecked = "";
foreach (TreeNode nd in Node.ChildNodes)
{
if (nd.Checked)
{
StrChecked += nd.Text + ",";
}
if (nd.ChildNodes.Count > 0)
{
StrChecked += GetSelectedChildNodeVText(nd);
}
}
StrChecked = StrChecked.TrimStart(',');
return StrChecked;
}
#endregion
#region===获取指定节点下已选择的文本内容===
///
/// 获取指定节点下已选择的文本内容
///
///
///
public static string GetSelectedChildNodeVValue(TreeNode Nodes)
{
string StrCheckedValue = "";
foreach (TreeNode nd in Nodes.ChildNodes)
{
if (nd.Checked)
{
StrCheckedValue += nd.Value + ",";
}
if (nd.ChildNodes.Count > 0)
{
StrCheckedValue += GetSelectedChildNodeVValue(nd);
}
}
StrCheckedValue = StrCheckedValue.TrimStart(',');
return StrCheckedValue;
}
#endregion
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯