在网上看到一个博客关于TreeList的,做了个小程序
博客地址:
http://blog.csdn.net/fwj380891124/article/details/6888077
显示不出来数据,大家看看是哪里有问题
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public string connectionString = "server=.;database=Room;uid=sa;pwd=sa";
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connectionString);
con.Open();
string sqltxt = "select * from dbo.house";
SqlCommand cmd = new SqlCommand(sqltxt, con);
cmd.ExecuteNonQuery();
BindData();
con.Close();
}
private void BindData()
{
DataTable dtHourse = new DataTable("house");
this.treeListHouse.DataSource = dtHourse.TableName;
treeListHouse.KeyFieldName = "OfficeID";
//tlOffice.DataMember = "OfficeName";
//treeListHouse.Columns["OfficeName"].Caption = "商品名称";
treeListHouse.ParentFieldName = "ParentOfficeID";
}
DataTable dtHourse = new DataTable("house");
this.treeListHouse.DataSource = dtHourse.TableName;
你的dataTable是你自己new的,不是从数据库里面读出来的
DataTable dtHourse = new DataTable("house");
this.treeListHouse.DataSource = dtHourse.TableName;
DataTable dtHourse = new DataTable("house"); 自己new的会有数据吗?
DataSource = dtHourse.TableName; 合理吗?