日期:2014-05-18  浏览次数:20938 次

求Treeview控件的例子和使用方法
RT

------解决方案--------------------
//this.treeView1.Nodes.AddRange(new TreeNode[] {
// new TreeNode("中国直辖市", new TreeNode[] {
// new TreeNode("北京市", new TreeNode[] {
// new TreeNode("东城区"), new TreeNode("西城区"),new TreeNode("朝阳区")}),
// new TreeNode("上海市", new TreeNode[] {new TreeNode("长宁区"),
// new TreeNode("黄埔区"), new TreeNode("浦东区")}),
// new TreeNode("重庆市", new TreeNode[] {
// new TreeNode("长寿区", new TreeNode[] {new TreeNode("云台镇"),
// new TreeNode("凤城镇", new TreeNode[] {new TreeNode("黄桷湾"),new TreeNode("关口")})}),
// new TreeNode("渝北区"),new TreeNode("北碚区")})})});
//this.treeView1.AllowDrop = true;
//this.treeView1.ExpandAll();

msdn上很全...

------解决方案--------------------
#region 树视图
private void InitTree(TreeNodeCollection Nds,string superior)
{
try
{
//声明节点
TreeNode tmpNd;
//取得下一级子节点
DataRow[] rows=_dv.Table.Select("parent_breed_id="+superior);
foreach(DataRow row in rows)
{
tmpNd=new TreeNode();

tmpNd.Text=row["breed_name"].ToString()+"["+row["id"].ToString()+"]";
//添加节点
Nds.Add(tmpNd);
//得到下一级子节点
InitTree(tmpNd.Nodes,row["id"].ToString());
}
}
catch(Exception ex)
{
string ss=ex.Message;
}
}


private void datatree()
{
_dv=w.getStandardTree1().Tables[0].DefaultView;
InitTree(treeView1.Nodes,"0");
}
#endregion
------解决方案--------------------


private void treeView1_ItemDrag(object sender, ItemDragEventArgs e)
{
this.treeView1.DoDragDrop(e.Item, DragDropEffects.Move);
}

private void treeView1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof (TreeNode)))
{
TreeNode parent = treeView1.GetNodeAt(treeView1.PointToClient(new Point(e.X,e.Y)));

TreeNode node = (TreeNode)e.Data.GetData(typeof(TreeNode));
if (node.Parent == null)
{
node.TreeView.Nodes.Remove(node);
}
else
{
node.Parent.Nodes.Remove(node);
}

if (parent != null)
{
parent.Nodes.Add(node);
}
else
{
treeView1.Nodes.Add(node);
}
}
}

private void treeView1_DragOver(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(TreeNode)))
{
e.Effect = DragDropEffects.Move;
}
}

节点拖放....引用(begincsdn )
------解决方案--------------------
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;