treeview控件,知道node的value和text,怎么获取id
public void grandsonnode(TreeNode childnode, string tt)
{
DataTable dt = bindtr().Tables[0];
DataRow[] rows = dt.Select("moduleid='" + childnode.Parent.Value + "' and childid ='" + childnode.Value + "'");
foreach (DataRow row in rows)
{
TreeNode node = new TreeNode();
node.Text = row["OperateName"].ToString();//假设node.text=修改
node.Value = row["OperateCode"].ToString();//假设node.value=111
node.Expanded = false;
childnode.ChildNodes.Add(node);
Checked(childnode, node.Parent.Value,node .Value );
}
}
public bool Checked(TreeNode tn, string sheettypeid,string operatecode)
{
bool aaa = false;
DataTable dt = operatorright().Tables[0];
DataRow[] rows = dt.Select("sheettypeid='" + sheettypeid + "' and operatecode ='" + operatecode + "'");
if (rows.Length > 0)
{
tn.ChildNodes[k].Checked = true; //k怎么定位到node.value=111的id,并将checked设置为true?
tn.Checked = true;
tn.Parent.Checked = true;
}
请问 tn.ChildNodes[k].Checked = true; //k怎么定位到node.value=111的id,并将checked设置为true?
------解决方案--------------------
合并一下,类型于这个样子,可能dt2.Select("sheettypeid='" + sheettypeid + "' and operatecode ='" + operatecode + "'");里的sheettypeid 需要改一下
public void grandsonnode(TreeNode childnode, string tt)
{
DataTable dt = bindtr().Tables[0];
DataRow[] rows = dt.Select("moduleid='" + childnode.Parent.Value + "' and childid ='" + childnode.Value + "'");
foreach (DataRow row in rows)
{
TreeNode node = new TreeNode();
node.Text = row["OperateName"].ToString();//假设node.text=修改
node.Value = row["OperateCode"].ToString();//假设node.value=111
node.Expanded = false;
childnode.ChildNodes.Add(node);
DataTable dt2 = operatorright().Tables[0];
DataRow[] rows2 = dt2.Select("sheettypeid='" + sheettypeid + "' and operatecode ='" + operatecode + "'");
if (rows2.Length > 0)
{
node.Checked = true; //k怎么定位到node.value=111的id,并将checked设置为true?
tn.Checked = true;
tn.Parent.Checked = true;
}
}
------解决方案--------------------