• Telerik RadTreeListView示例


            <telerik:RadTreeListView Margin="3"
                    Name="tv" Grid.Row="2"
                    telerik:StyleManager.Theme="Office_Silver" 
                    AutoGenerateColumns="False" 
                    IsFilteringAllowed="False" 
                    HierarchyColumnIndex="1"
                    RowIndicatorVisibility="Collapsed"
                    SelectedCellsChanged="tv_SelectedCellsChanged"
                    IsReadOnly="True">
                <telerik:RadTreeListView.ChildTableDefinitions>
                    <telerik:TreeListViewTableDefinition ItemsSource="{Binding Items}" />
                </telerik:RadTreeListView.ChildTableDefinitions>
                <telerik:RadTreeListView.Columns>
                    <telerik:GridViewSelectColumn />
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding ID}" Header="分类编号" IsVisible="False"/>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding CategoryName}" Header="分类名称" Width="300" />
                </telerik:RadTreeListView.Columns>
            </telerik:RadTreeListView>
    using System;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.Collections.ObjectModel;
    
    namespace SGSGHome.Views.File
    {
        public class CatItem
        {
            public long ID { get; set; }
            public string CategoryName { get; set; }
            public long? ParentID { get; set; }
            public ObservableCollection<CatItem> Items { get; set; }
            public CatItem(long id, string catName, long? parentID)
            {
                this.ID = id;
                this.CategoryName = catName;
                this.ParentID = parentID;
                this.Items = new ObservableCollection<CatItem>();
            }
        }
    }
            public IList<CoreService.FileCategory> CatList { get; set; }
    
            void client_GetFileCategoryListCompleted(object sender, CoreService.GetFileCategoryListCompletedEventArgs e)
            {
                //递归填充TreeListView
                this.CatList = e.Result;
    
                var root = CatList.First(x => x.ParentID == null);
                var rootItem = new CatItem(root.ID, root.CategoryName, null);
                AddChild(root.ID, rootItem);
                tv.ItemsSource = new ObservableCollection<CatItem>() { rootItem };
                tv.AutoExpandItems = true;
            }
    
            //递归方法
            void AddChild(long parentID, CatItem parentItem)
            {
                var filterList = CatList.Where(x => x.ParentID == parentID).ToList();
    
                foreach (var tt in filterList)
                {
                    var childItem = new CatItem(tt.ID, tt.CategoryName, tt.ParentID);
                    parentItem.Items.Add(childItem);
                    var childrenList = CatList.Where(x => x.ParentID == tt.ID).ToList();
                    if (childrenList.Count > 0)
                    {
                        AddChild(tt.ID, childItem);
                    }
                }
            }
  • 相关阅读:
    数据库(MySQL):事务
    数据库(MySQL):存储引擎
    操作系统:虚拟存储器
    操作系统:内存管理
    操作系统:进程与线程
    近期目标
    计算机网络:TCP三次握手、四次挥手
    计算机网络:OSI与TCP/IP各层的结构与功能,都有哪些协议
    计算机网络:从输入URL到页面加载
    Java:JVM
  • 原文地址:https://www.cnblogs.com/ncore/p/2784553.html
Copyright © 2020-2023  润新知