VS2005里TreeView怎么绑定?
我的代码如下
private void InitTreeView()
{
for (int i=0;i <GetBigType ().Rows .Count ;i ++)
{
DataTable dt=GetBigType();
TreeNode node = new TreeNode();
node.Expanded = false;//设置节点是否展开,取反
//look this code run
node.Text =dt.rows[i][ "bigname "].ToString ();
node.Value = dt.Rows[i][ "TradeBigTypeid "].ToString();
this.MyTreeView.Nodes.Add(node);
}
}
现在我要绑定下面的相应二级节点和三级节点,怎么弄?谢谢各位高手了!
------解决方案--------------------建立节点之间的父子关系
用递归函数绑定
------解决方案--------------------using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string C = " ";
int A = 0;
DataSet Da=new DataSet();
Da.ReadXml( "22.xml ");
MessageBox.Show(Da.Tables[0].TableName);
Da.Tables[0].DefaultView.Sort = "group ";
for (int B = 0; B <= Da.Tables[0].Rows.Count-1; B++)
{
if (C != (String)Da.Tables[0].DefaultView[B][ "group "])
{
A++;
C = (String)Da.Tables[0].DefaultView[B][ "group "];
this.treeView1.Nodes.Add((String)Da.Tables[0].DefaultView[B][ "group "]);
}
this.treeView1.Nodes[A - 1].Nodes.Add((String)Da.Tables[0].DefaultView[B][ "friend "]);
}
}
}
}
改下应该没问题拉
------解决方案--------------------递归就是写个方法,这个方法中自已调用自已。