如何填充 TreeView 的节点? (C# winforms)
我有一个 SQL Server Compact Edition 数据库文件,我想将其中的所有表作为节点显示到 Windows 应用程序中的 TreeView 控件中。
不幸的是,我不知道该怎么做。
这就是我现在所拥有的:
private void PopulateTreeView()
{
SqlCeCommand cmd = new SqlCeCommand();
try
{
using (SqlCeConnection conn = new SqlCeConnection("Data Source=" + connString))
{
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES";
conn.Open();
cmd.Connection = conn;
cmd.ExecuteNonQuery();
// Don't know what's next...
}
}
catch (Exception x)
{
MessageBox.Show(x.GetBaseException().ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
cmd.Dispose();
}
}
I have a SQL Server Compact Edition Database file, and I want to display all the tables on it as nodes into a TreeView control in my windows application.
Unfortunately, I don't know how to.
This is what I have now:
private void PopulateTreeView()
{
SqlCeCommand cmd = new SqlCeCommand();
try
{
using (SqlCeConnection conn = new SqlCeConnection("Data Source=" + connString))
{
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES";
conn.Open();
cmd.Connection = conn;
cmd.ExecuteNonQuery();
// Don't know what's next...
}
}
catch (Exception x)
{
MessageBox.Show(x.GetBaseException().ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
cmd.Dispose();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样的事情
你可以通过节点创建变得更加有趣。查看各种构造函数,看看您想要什么。
something like
you can get fancier with the node creation. Have a look at the various constructors to see what you want.