我想在我的windowsform中以树形视图显示我的数据库表 [英] i want to display my database tables in tree view in my windowsform
本文介绍了我想在我的windowsform中以树形视图显示我的数据库表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
i我的数据库中有一张桌子
1)admin
2)用户
3)角色
i希望以动态形式在树形视图中显示它plz帮助我
i have a tables in my database
1)admin
2)users
3)roles
i want to display it in tree view in my form dynamically plz help me
推荐答案
在表单上初始化TreeView。您可以通过在Visual Studio中从控件栏拖放树视图控件来轻松完成此操作。通常通过拖放操作将其命名为treeView1。之后获取要在树视图中显示的表列表;更好地从数据库中提取该列表。当您有列表时,可以使用以下代码将节点分配给树视图:(假设您在列表中有表名列表)
foreach( tablesNameList中的字符串tableName)// tablesNameList是包含表的所有名称的列表
{
TreeNode treeNode = new TreeNode(tableName);
//如果您想为每个节点添加图标,或者您想要分配一些其他属性,您可以在此处执行此操作。
//之后,您需要将该节点添加到treeview控件。你可以这样做
treeView1.Nodes.Add(treeNode); //此行将节点添加到树视图控件。
}
希望我已经回答了你的问题。
Initialize the TreeView on the form. You can do this easily by dragging/dropping the treeview control from the control-bar in Visual Studio. Usually it is named as treeView1 when you do it by dragging/dropping. After that get the list of tables you want to display in the treeview; better pull that list from the database. When you have the list, you can use the following code to assign nodes to the treeview: (Assuming that you have list of table names in a List)
foreach(string tableName in tablesNameList) //tablesNameList is the list containing all the names of the tables
{
TreeNode treeNode = new TreeNode(tableName);
// if you want to add icon against each node or you want to assign some other properties you can do it here.
//After that you need to add that node to the treeview control. you can do it as below
treeView1.Nodes.Add(treeNode); // this line will add the node to the treeview control.
}
Hope I have answered your question.
这篇关于我想在我的windowsform中以树形视图显示我的数据库表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文