我需要将列表从文件加载到TreeView方面的帮助 [英] I need help with loading a list from a file into a TreeView
本文介绍了我需要将列表从文件加载到TreeView方面的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void addTreeNode()
{
try
{
ofdInput.ShowDialog();
StreamReader srInput = new StreamReader(ofdInput.FileName);
tvLinks.Nodes.Clear();
pbIcon.Image = null;
for (int X = 1; X <= File.ReadLines(ofdInput.FileName).Count(); X++)
{
try
{
MessageBox.Show(X + " / " + File.ReadLines(ofdInput.FileName).Count());
string URL = srInput.ReadLine();
Uri IconLocation = new Uri(URL);
string SavePath = IconLocation.Host.Replace("www.", "").Remove(IconLocation.Host.Replace("www.", "").LastIndexOf(".")) + ".ico";
if (!File.Exists(SavePath))
{
WebClient Client = new WebClient();
Client.DownloadFile("http://" + IconLocation.Host + "/favicon.ico", SavePath);
}
pbIcon.ImageLocation = SavePath;
if (tvLinks.Nodes.Count > 0)
{
for (int I = 0; I <= tvLinks.Nodes.Count; I++)
{
if (tvLinks.Nodes[I].Text == IconLocation.Host.ToString())
{
tvLinks.Nodes[I].Nodes.Add(srInput.ReadLine());
break;
}
else if (I == tvLinks.Nodes.Count - 1)
{
tvLinks.Nodes.Add(IconLocation.Host).Nodes.Add(srInput.ReadLine());
break;
}
}
}
else
{
tvLinks.Nodes.Add(IconLocation.Host).Nodes.Add(srInput.ReadLine());
}
}
catch
{
}
}
}
catch
{
}
}
推荐答案
检查这些博客
使用"TreeView"控件Asp.net 2.0绑定数据 [ http://weblogs.asp.net/scottgu/pages/ASP.NET-2.0-Tips_2C00_-Tricks_2C00_-Recipes-and-Gotchas.aspx [
check these blogs
Binding Data With ‘TreeView’ Control Asp.net 2.0[^]
http://weblogs.asp.net/scottgu/pages/ASP.NET-2.0-Tips_2C00_-Tricks_2C00_-Recipes-and-Gotchas.aspx[^]
--NDK
我觉得你的问题在这里
i think u problem is here
if (tvLinks.Nodes[I].Text == IconLocation.Host.ToString())
{
tvLinks.Nodes[I].Nodes.Add(srInput.ReadLine());
break;
}
else if (I == tvLinks.Nodes.Count - 1)
{
tvLinks.Nodes.Add(IconLocation.Host).Nodes.Add(srInput.ReadLine());
break;
}
您最确定的是,每个
You most asure that u are parsing well the info in ur text file en every
tvLinks.Nodes[I].Text
都建议您对文本文件中的信息进行很好的解析:P
a debug is recommended :P
保存和加载TreeView内容 [
这篇关于我需要将列表从文件加载到TreeView方面的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文