列表框递归分组 [英] ListBox Recursive Grouping
问题描述
你好,
我在Sql Server数据库中有数据,必须将其加载到列表框控件中.此操作已完成,但是现在我被要求将这些数据分组为甘特图所示的数据
这是我桌子的结构
CodeDossier -------- CodeParent(父母代码)-------- Niveau(级别)--------Libellé(标签)
:::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::
A ------------------------空------------------------ ----------- 1 ------------------------标签1 --------
A01 ---------------------- A -------------------------- ----------- 2 ------------------------标签2 --------
A02 ---------------------- A -------------------------- ----------- 2 ------------------------标签3 --------
A021 ------------------- A02 ----------------------------- ------ 3 ------------------------标签31 --------
A022 ------------------- A02 ----------------------------- ------ 3 ------------------------标签32 --------
B ------------------------空------------------------ ----------- 1 ------------------------标签4 --------
B01 --------------------- B --------------------------- ----------- 2 ------------------------标签5 --------
B02 --------------------- B --------------------------- ----------- 2 ------------------------标签6 --------
B03 --------------------- B --------------------------- ----------- 2 ------------------------标签7 --------
C -----------------------空------------------------- ----------- 1 ------------------------标签8 --------
C01 --------------------- C --------------------------- ----------- 2 ------------------------标签9 --------
而且我必须像这样在列表框中显示这些数据:
CodeDossier库
+ A标签1(4)
-A01标签2
+ A02标签3
-A021标签31
-A022标签32
+ B标签4
+ B01标签5
+ B02标签6
+ B03标签7
+ C
+ C01标签8
我花了三天时间,但是不幸的是我找不到解决方案.我的导演希望我用XAML来做.希望有人能帮助我.感谢
Hello,
I have data in a Sql Server database that i have to load in a listbox control.This is done, but now i was asked to group these data as data shown in a Gantt Diagram
This the structure of my table
CodeDossier--------CodeParent(Parent Code)--------Niveau(Level)--------Libellé(Label)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
A------------------------Null-----------------------------------1------------------------Label 1--------
A01----------------------A-------------------------------------2------------------------Label 2--------
A02----------------------A-------------------------------------2------------------------Label 3--------
A021-------------------A02-----------------------------------3------------------------Label 31--------
A022-------------------A02-----------------------------------3------------------------Label 32--------
B------------------------Null-----------------------------------1------------------------Label 4--------
B01---------------------B--------------------------------------2------------------------Label 5--------
B02---------------------B--------------------------------------2------------------------Label 6--------
B03---------------------B--------------------------------------2------------------------Label 7--------
C-----------------------Null------------------------------------1------------------------Label 8--------
C01---------------------C--------------------------------------2------------------------Label 9--------
and i have to present these data in the listbox like this:
CodeDossier Lib
+A Label 1 (4)
-A01 Label 2
+A02 Label 3
-A021 Label 31
-A022 Label 32
+B Label 4
+B01 Label 5
+B02 Label 6
+B03 Label 7
+C
+C01 Label 8
i spent three days on it but unfortunately i could''nt find solution for it.my director want that i do it in xaml. Hope that someone could help me. Thank
推荐答案
对于SQL 2005及更高版本中的公用表表达式(CTE),这似乎是一个很好的候选人.
这就是我得到的.它已经结束了,但是我相信您需要对应用程序进行一些排序,才能使其达到您想要的效果.很抱歉,如果它不能满足您的需求.
This looks like a great candiate for Common Table Expressions (CTE) available in SQL 2005 and up.
Here is what I got. It''s close, but I believe you need to do some application side sorting to get it to what you want. Sorry if it doesn''t meet your needs.
declare @tree table(id int, parent_id int)
insert into @tree
values(1, null)
insert into @tree
values(2, null)
insert into @tree
values(6, 3);
insert into @tree
values(3, 1)
insert into @tree
values(4, 2)
insert into @tree
values(5, 1);
WITH RecurseTable(MyId, ParentId, TagLevel)
AS
(
SELECT id, ISNULL(parent_id, 0), 0
FROM @tree
WHERE parent_id IS NULL
UNION ALL
SELECT T.id, T.parent_id, TagLevel + 1
FROM @tree T
INNER JOIN RecurseTable R ON T.parent_id = R.MyId
)
select *
from RecurseTable
我看到了一些示例,但一无所获.很高兴您能帮助我.谢谢
I saw some samples but i found nothing.I''ll be happy that you help me. Thank
在您的情况下,数据更具逻辑性. WPF中的ListBox允许使用CollectionView进行分组.您可以将组添加到您的collectionView.GroupDescrption.Add
但是您的情况需要动态分组.为什么不使用Hierarachical DataTemplate.我在考虑的是TreeView,而不是ListView.
In your case the data is more logical. ListBox in WPF allows grouping using CollectionView. You can add groups to your collectionView.GroupDescrption.Add
But your case requires a dynamic grouping. Why dont you use Hierarachical DataTemplate. I am thinking of TreeView rather than ListView in your case.
这篇关于列表框递归分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!