问题描述
Hello All
我正在尝试在c#中填充Treeview,它有三个级别。我有三个表,分类,商店和股票。表格引用如下;
股票
stockID
stockName
catID
storID
类别
catID
catName
商店
storID
storeNam
我运行sql存储过程使用以下代码检索股票详细信息;
选择a.stockID,a.stockName,b.catName,c.storeName
来自股票a
内连接类别b on a.catID = b.catID
内连接存储c on a.storeID = c.storeID
现在我想在这样的Treeview中显示查询结果;
+ storeName
..... + catName
.......... stockName
例子
+ Newyork商店
..... +水果
..........橙色
我怎样才能在c#中做到这一点,我到处都看,但我发现的只有g给我两个级别。
非常感谢提前。
Hello All
I am trying to populate a Treeview in c# which has three levels. I have three tables for Category, Store and Stock. the tables are referenced as follows;
Stock
stockID
stockName
catID
storID
Category
catID
catName
Store
storID
storeNam
I run an sql stored procedure with the following code to retrieve the stock details;
select a.stockID, a.stockName, b.catName, c.storeName
from Stock a
inner join Category b on a.catID = b.catID
inner join Store c on a.storeID = c.storeID
Now i want to desplay the result of the query in a Treeview like this;
+storeName
.....+catName
..........stockName
Example
+Newyork store
.....+Fruits
..........Orange
How can i do this in c#, i have looked everywhere but what i have found is only giving me two levels.
Many thanks in advance.
推荐答案
public static void ListToTreeview(TreeView treeview, List ListOfRows)
{
// Place the root node to work from in the treeview
TreeNode root = new TreeNode(ListOfRows[0]);
TreeNode node;
treeview.Nodes.Add(root);
// Loop through each row
foreach(string s in ListOfRows)
{
node = root;
foreach (string level in samenvoegveld.Split('.'))
{
node = AddNode(node, level);
}
}
}
这篇关于从C#中的sql数据源填充Treeview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!