日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

silverlight中递归构造无限级树treeview+checkbox

發(fā)布時間:2025/4/14 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 silverlight中递归构造无限级树treeview+checkbox 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

?

兩個實體,其實一個實體也能構(gòu)造出來,我這里是為了增加一個 checkbox

//第一個實體

public class person
{
public int no { get; set; }
public string name { get; set; }
public ObservableCollection<person> child { get; set; }
}

//第二個實體

public class inst ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ****
{
public int instNo { get; set; }       ****
public string instName { get; set; }    ****
public int personID { get; set; }      ***
}

//xaml界面就放了一個 ?treeview

<Grid x:Name="LayoutRoot" Background="White">
<sdk:TreeView x:Name="tvshow" HorizontalAlignment="Left" Height="280" Margin="10,10,0,0" VerticalAlignment="Top" Width="367"/>

</Grid>

//cs頁面

ObservableCollection<person> List = null;//第一個實體的集合
ObservableCollection<inst> instList = null;//第二個實體的集合 ? ? ?****
public MainPage()
{
InitializeComponent();
List = new ObservableCollection<person>();
instList = new ObservableCollection<inst>();        ****
person p1 = new person() { no=1,name="1",child=new ObservableCollection<person>()};
person p2 = new person() { no = 2, name = "2", child = new ObservableCollection<person>() };
person p3 = new person() { no = 3, name = "3", child = new ObservableCollection<person>() };
person p4 = new person() { no = 4, name = "4", child = new ObservableCollection<person>() };
person p5 = new person() { no = 5, name = "5", child = new ObservableCollection<person>() };


inst inst1 = new inst() { instNo = 1,personID=1 ,instName = "jigou1" }; ? ? ***
inst inst2 = new inst() { instNo = 2, personID = 1, instName = "jigou2" }; ?***
inst inst3 = new inst() { instNo = 3, personID = 1, instName = "jigou3" }; ?***
inst inst4 = new inst() { instNo = 4, personID = 1, instName = "jigou4" }; ?***
inst inst5 = new inst() { instNo = 5, personID = 2, instName = "jigou5" }; ?***
inst inst6 = new inst() { instNo = 6, personID = 3, instName = "jigou6" }; ?***
inst inst7 = new inst() { instNo = 7, personID = 4, instName = "jigou7" }; ?***
p3.child.Add(p4);
p2.child.Add(p3);
List.Add(p1);
List.Add(p2);
List.Add(p5);

instList.Add(inst1); instList.Add(inst2); instList.Add(inst3); instList.Add(inst4); instList.Add(inst5); instList.Add(inst6); instList.Add(inst7); ? ***

//生成樹
foreach (var item in List)
{
tvshow.Items.Add(initView(item));
}
}

//遞歸函數(shù)
TreeViewItem initView(person p)
{
TreeViewItem it = new TreeViewItem();
it.Header = p.name;
foreach (var item in instList)
{
if (p.no == item.personID) ? ? ? ? ? ? ? ? ? ? ? ***
{
TreeViewItem cbt = new TreeViewItem(); ? ***
CheckBox cb = new CheckBox(); ? ? ? ? ? ? ?***
cb.Content = item.instName; ? ? ? ? ? ? ? ? ? ?***
cbt.Header = cb; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ***
it.Items.Add(cbt); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ***
}
}
if (p.child.Count>0)
{
foreach (var item in p.child)
{
it.Items.Add(initView(item));
}
}
return it;
}

運行效果:

?

如果不想 進行 復(fù)雜的 構(gòu)造, 只生成第一的 ?無限級樹, 可以把我 后面加*號的 部分 ?注釋掉,就可以了。

轉(zhuǎn)載于:https://www.cnblogs.com/qiancheng/p/3745536.html

《新程序員》:云原生和全面數(shù)字化實踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

總結(jié)

以上是生活随笔為你收集整理的silverlight中递归构造无限级树treeview+checkbox的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。