小妹真诚求教!TreeView如何设计无级菜单和展现菜单!
我想做一个无级菜单!结构如下,我不会设计数据库!请师哥们帮忙!
再有数据库设计好之后,如何取出数据显现在TreeView控件上!
谢谢各位师哥了!
中国
|—北京市
|—天津市
|—上海市
|—河北省
|—石家庄市
|—XX县
|—邯郸市
|—河南省
|—郑州市
|—新乡市
|—广东省
|—广州市
|—深圳市
|—XX县
谢谢各位师哥!请代码明示!C#!小妹我在这里不胜感激!
------解决方案--------------------在数据库中建一个表:如下! PID说父接点意思
ID PID Name Url
标识 父标识 名字 链接
如:
1 0 中国 #
2 1 河北省 #
连接数据库后的绑定代码:BindTree(this.TreeView1.Nodes, 0);//this.TreeView1就是你的TreeView控件
类
void BindTree(TreeNodeCollection nds, int parentId)
{
TreeNode tn = null;
foreach (DataRow dr in BLL.DO.TreeviewItem().Select( "PId= " + parentId, "ListID asc "))
{
tn = new TreeNode(dr[ "Name "].ToString(), dr[ "id "].ToString(), null, dr[ "Url "].ToString(), "fmain ");
//tn.ShowCheckBox = true;
nds.Add(tn);
BindTree(tn.ChildNodes, Convert.ToInt32(dr[ "id "]));
}
}
不明白再问我,记得给分^_^ !
------解决方案--------------------结构
bh name parent
1001 广东
100101 广州 1001
100102 中山 1001
10010201 古镇 100102
Dim dtconn As SqlConnection = New SqlConnection( "data source=.;uid=sa;pwd=aaaaaa;database=tree; ")
Dim dtcmd As SqlCommand
Dim dtreader As SqlDataReader
Dim dtcm As SqlCommand
Dim dtread As SqlDataReader
Dim dtSql As String = "select * from tree order by bh "
dtcmd = New SqlCommand(dtSql, dtconn)
dtconn.Open()
dtreader = dtcmd.ExecuteReader()
While dtreader.Read
Dim root As New TreeNode
root.Text = dtreader( "mc ")
root.Value = dtreader( "bh ")
If dtreader( "parent ") = " " Then
TreeView1.Nodes.Add(root)
End If
FillTree(root)
End While
dtreader.Close()
Sub FillTree(ByVal root As TreeNode)
Dim dtconn As SqlConnection = New SqlConnection( "data source=.;uid=sa;pwd=aaaaaa;database=tree; ")
Dim dtcmd As SqlCommand
Dim dtreader As SqlDataReader
Dim dtSql As String = "select * from tree where parent= ' " + root.Value + " ' "
dtcmd = New SqlCommand(dtSql, dtconn)
dtconn.Open()
dtreader = dtcmd.ExecuteReader()
While dtreader.Read
Dim childroot As New TreeNode
childroot.Text = dtreader( "mc ")