我想将数据从记事本传输到listview

时间:2016-07-14 08:35:12

标签: c# listview

我有一个创建文件夹的项目,在这些文件夹中,新文本文件是用里面的一些内容创建的。

它会创建如下文本文件:

versionname: 1.3.2
$
explanation:"something that we type in program"
$
date:14.07.2016

我想创建一个listview和3列,我想要将版本名称,解释和日期加载到这些列中,并在每次启动程序时键入 添加文件夹和代码是这样的:

PS:我没有使用日期表,因为我不想

感谢您的关注

string klasor = textBox1.Text;

Directory.CreateDirectory("C:/Users/user/Desktop/");
Directory.CreateDirectory("C:/Users/user/Desktop/proje/Versiyonlar/"+klasor);

//string Dizinpath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
StreamWriter Dosya1=File.CreateText("C:\\Users\\user\\Desktop\\proje\\Versiyonlar\\"+klasor+"\\"+klasor+".txt");
Dosya1.Close();

StreamWriter SW = new StreamWriter("C:\\Users\\user\\Desktop\\proje\\Versiyonlar\\"+klasor+"\\"+klasor+".txt");
SW.WriteLine("Versiyon no:" + textBox1.Text);
SW.WriteLine("$");
SW.WriteLine("Açıklama:"+textBox2.Text);
SW.WriteLine("$");
SW.WriteLine("Eklenme tarihi:"+dateTimePicker1.Text);
SW.Close();

MessageBox.Show("Versiyon ve açıklama eklendi");

这是添加文件夹和txt文件的代码现在我想将该txt文件信息添加到listview

1 个答案:

答案 0 :(得分:0)

 listView1.View = View.Details;
        listView1.Columns.Add("Versiyon No", 133, HorizontalAlignment.Left);
        listView1.Columns.Add("Açıklama", 240, HorizontalAlignment.Left);
        listView1.Columns.Add("Tarih", 150, HorizontalAlignment.Left);

        using (StreamReader sr = new StreamReader("C:\\Users\\user\\Desktop\\proje\\Versiyonlar\\1.1.2\\" + "1.1.2.txt", Encoding.Default))
            {
            string line;
            while ((line = sr.ReadLine()) != null)
            {
                int sira = listView1.Items.Count;


                listView1.Items.Add(line.Split(',')[0]);
                listView1.Items[sira].SubItems.Add(line.Split(',')[1]);
                listView1.Items[sira].SubItems.Add(line.Split(',')[2]);
                listView1.Items[sira].SubItems.Add(line.Split(',')[3]);
                listView1.Items[sira].SubItems.Add(line.Split(',')[4]);

            }

        }

我想我刚刚解决了这样的问题