C# StreamReader到树视图
我有一个文本文件(.txt),其结构如下:C# StreamReader到树视图,c#,wpf,treeview,streamreader,C#,Wpf,Treeview,Streamreader,我有一个文本文件(.txt),其结构如下: [阿尔法][好极了][查理] [好极了][阿尔法][查理][三角洲][好极了] [好极了][阿尔法][查理][探戈] 层次结构如下: 阿尔法>布拉沃>查理 布拉沃>阿尔法>查理>三角洲>布拉沃 ------------------------------------->探戈 此文本文件可能有100-200行。我想使用StreamReader读入这些行,然后在树视图中显示这些行 到目前为止,我已经使用StreamReader成功地读取了文件,并使用.
- [阿尔法][好极了][查理]
- [好极了][阿尔法][查理][三角洲][好极了]
- [好极了][阿尔法][查理][探戈]
string currentFilter = cbTagFilter.Text;
Console.WriteLine(currentFilter);
IEnumerable<string> lines = File.ReadLines(tbFileSelection.Text).Where(line => line.StartsWith(currentFilter));
foreach (string line in lines)
{
lbContents.Items.Add(line);
Console.WriteLine(line);
}
string currentFilter=cbTagFilter.Text;
控制台写入线(currentFilter);
IEnumerable lines=File.ReadLines(tbFileSelection.Text).Where(line=>line.StartsWith(currentFilter));
foreach(行中的字符串行)
{
lbContents.Items.Add(行);
控制台写入线(行);
}
创建一个表示父子关系的类,并生成这些对象的列表。然后使用ItemsSource
属性将列表绑定到TreeView
控件,并使用hierarchycaldatatemplate
定义TreeView
中项目的外观