gpt4 book ai didi

C# 加载.txt 文件并在 ListView 中显示

转载 作者:太空宇宙 更新时间:2023-11-03 23:26:45 25 4
gpt4 key购买 nike

所以我要做的是加载一个 .txt 文件,一旦加载了 .txt 文件,它将在 listView 中显示 .txt 文件的内容。

这是我的加载代码。

        List<String> proxies = new List<string>();
private void loadProxiesToolStripMenuItem_Click(object sender, EventArgs e)
{
loadProxies();
}

private void loadProxies()
{
this.Invoke(new MethodInvoker(delegate
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "TXT files|*.txt";
ofd.Title = "Load Proxies";
var dialogResult = ofd.ShowDialog();
if (dialogResult == DialogResult.OK)
{
proxies = new List<string>();
Parallel.ForEach(System.IO.File.ReadLines(ofd.FileName), (line, _, lineNumber) =>
{
if (line.Contains(":"))
{
//loadedCombo.Add(line);
proxies.Add(line);
}
else
{
//MessageBox.Show("Hmm, thats not a combolist - please try again");
}
});
}

txt_proxies.Text = "Proxies Loaded: " + proxies.Count.ToString();

}));
}

我希望它显示在名为“proxyView”的 ListView 中。

所以我想说的是,我可以加载 .txt 并更改计数,但不会将 .txt 文件中的内容添加到 ListView 中。

非常感谢。

最佳答案

将项目添加到 ListView你可以使用 yourListView.Items.Add(text)

例如:

private void loadProxies()
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "TXT files|*.txt";
ofd.Title = "Load Proxies";
var dialogResult = ofd.ShowDialog();
if (dialogResult == DialogResult.OK)
{
foreach (var line in System.IO.File.ReadLines(ofd.FileName))
{
if (line.Contains(":"))
proxyView.Items.Add(line);
}
}
}

关于C# 加载.txt 文件并在 ListView 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33589531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com