将.txt文件加载到列表视图中,[帮助] [VB.NET] [英] Load .txt file into listview, [HELP] [VB.NET]
问题描述
你好
好的,首先我使用Visual Studio 2010,即制作该应用的应用程序
您有一个文本框和一个名为打开列表"的按钮,当您单击它时,它将从文本框位置打开.txt文件.
你懂我吗?好的
现在.txt文件看起来像
setting1:true; setting2:false; setting3:true;
因此其设置为:[true,false]或其他选项,例如字体是否为font:tahoma或size .. etc
如此和;分隔每个设置
现在的问题是,如何"将这个文件加载到列表视图中,并包含设置,值"和
我需要能够选择其中之一,并且能够通过按钮Delete
删除设置.
请告诉我如何,我需要这个:(
ty
hello
ok, first i use visual studio 2010, im making app that
you have a textbox and a button called Open List, when you click on it, it will Open the .txt file from the textbox location.
you got me? ok
now the .txt file looks like
setting1:true;setting2:false;setting3:true;
so its Setting : [true,false] or might be other options like if font it will be font:tahoma or size .. etc
so and the ; seperates each setting
now the thing is, "how" can i load this file into a listview, with "Setting, Value" thing, and also
i need to be able to select one of them for example and be able to delete the setting, with a button Delete
please tell me how, i please need this :(
ty
推荐答案
ListView可能不是您要使用的-确实不是为那种事情设置的,除非您将每行显示为单独的字符串-根据您的描述,我认为这不是您要实现的目标.但是...
A ListView is probably not what you want to use - it really isn''t setup for that kind of thing, unless you display each line as a separate string - I don''t think from your description that that is what you are trying to achieve. But...
string rawData = @"setting1:true;setting2:false;setting3:true;";
或:
Or:
string rawData = File.ReadAllText(@"D:\Temp\Settings.txt");
然后:
Then:
string[] pairs = rawData.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string pair in pairs)
{
listView1.Items.Add(pair);
}
会做到的-
但是,使用更具结构化"的控件(例如DataGridView)可能会更好:
Will do it - sort of.
But you might be better off using a "more structured" control, such as a DataGridView:
string rawData = @"setting1:true;setting2:false;setting3:true;";
string[] pairs = rawData.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>();
foreach (string pair in pairs)
{
string[] kv = pair.Split(':');
list.Add(new KeyValuePair<string, string>(kv[0], kv[1]));
}
dataGridView1.DataSource = list;
这篇关于将.txt文件加载到列表视图中,[帮助] [VB.NET]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!