vb treeview控件中如何在选中地点处添加子节点
展开全部
//添加父节点
TreeView1.Nodes.Add(new TreeNode(reader[1].ToString(),reader[0].ToString()));
using (SqlConnection mycon = new SqlConnection(sqlstr))
{
mycon.Open();
SqlCommand mycom = new SqlCommand( "select id,dutyName from duty where deptID = @deptID ", mycon);
mycom.Parameters.Add( "@deptID ", reader[0].ToString());
SqlDataReader myreader = mycom.ExecuteReader();
while (myreader.Read())
{
//添加子节点
TreeView1.Nodes[i].ChildNodes.Add(new TreeNode(myreader[1].ToString(),myreader[0].ToString()));
using (SqlConnection sqlcon = new SqlConnection(sqlstr))
{
sqlcon.Open();
SqlCommand sqlcom = new SqlCommand( "select userID,username from userview where dutyID = @dutyID ", sqlcon);
sqlcom.Parameters.Add( "@dutyID ", myreader[0].ToString());
SqlDataReader sqlreader = sqlcom.ExecuteReader();
while (sqlreader.Read())
{
TreeView1.Nodes[i].ChildNodes[j].ChildNodes.Add(new TreeNode(sqlreader[1].ToString(),sqlreader[0].ToString()));
}
}
j = j + 1;
}
}
i = i + 1;
}
像这种代码一般能直接用的都不多的 你看下 自己再写
TreeView1.Nodes.Add(new TreeNode(reader[1].ToString(),reader[0].ToString()));
using (SqlConnection mycon = new SqlConnection(sqlstr))
{
mycon.Open();
SqlCommand mycom = new SqlCommand( "select id,dutyName from duty where deptID = @deptID ", mycon);
mycom.Parameters.Add( "@deptID ", reader[0].ToString());
SqlDataReader myreader = mycom.ExecuteReader();
while (myreader.Read())
{
//添加子节点
TreeView1.Nodes[i].ChildNodes.Add(new TreeNode(myreader[1].ToString(),myreader[0].ToString()));
using (SqlConnection sqlcon = new SqlConnection(sqlstr))
{
sqlcon.Open();
SqlCommand sqlcom = new SqlCommand( "select userID,username from userview where dutyID = @dutyID ", sqlcon);
sqlcom.Parameters.Add( "@dutyID ", myreader[0].ToString());
SqlDataReader sqlreader = sqlcom.ExecuteReader();
while (sqlreader.Read())
{
TreeView1.Nodes[i].ChildNodes[j].ChildNodes.Add(new TreeNode(sqlreader[1].ToString(),sqlreader[0].ToString()));
}
}
j = j + 1;
}
}
i = i + 1;
}
像这种代码一般能直接用的都不多的 你看下 自己再写
展开全部
给你段例子代码
Dim rootstr, leafstr As String
Dim tmpnode, xnode As Node
TreeView1.Nodes.Clear
rootstr = "root"
Set tmpnode = TreeView1.Nodes.Add(, tvwLast, rootstr, "bdz", 2)
leafstr = "ID1"
Set xnode = TreeView1.Nodes("root")
Set tmpnode = TreeView1.Nodes.Add(xnode.Index, tvwChild, leafstr, "AAA", 1)
Dim rootstr, leafstr As String
Dim tmpnode, xnode As Node
TreeView1.Nodes.Clear
rootstr = "root"
Set tmpnode = TreeView1.Nodes.Add(, tvwLast, rootstr, "bdz", 2)
leafstr = "ID1"
Set xnode = TreeView1.Nodes("root")
Set tmpnode = TreeView1.Nodes.Add(xnode.Index, tvwChild, leafstr, "AAA", 1)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询