关于treeview,帮看看哪里有问题。。初学者。。。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void AddNodes(DataTable dt, string id, string text, string pid)
{
DataRow[] dr = dt.Select("pid = '" + string.Empty + "'");
foreach (DataRow drv in dr)
{
TreeNode tn = new TreeNode();
tn.Text = drv[text].ToString();
tn.Tag = drv[id];
treeView1.Nodes.Add(tn);
AddChild(tn, dt, id, text, pid);
}
}
private void AddChild(TreeNode tn, DataTable dt, string id, string text, string pid)
{
DataRow[] dr = dt.Select("pid ='" + tn.Tag.ToString() + "'");
if (dr.Length > 0)
{
foreach (DataRow dr1 in dr)
{
TreeNode tnc = new TreeNode();
tnc.Text = dr1[Text].ToString();
tnc.Tag = dr1[id];
AddChild(tnc, dt, id, text, pid);
}
&