当前位置:网站首页>C#读写txt文件到listview
C#读写txt文件到listview
2022-06-22 08:01:00 【shixch】
C#读写txt文件到listview
读txt文件
private void button2_Click_2(object sender, EventArgs e)
{
string[] array = File.ReadAllLines(conf);
listView1.Items.Clear();
for (int i = 0; i < array.Length; i++)
{
if (array[i].Length > 0)//不添加空行
{
ListViewItem listviewItem = new ListViewItem();
string s = array[i].ToString();
//这里没有对格式是否符合要求进行判断,如果内容被修改成其他格式则会出异常的
string[] arr = s.Split(',');
listviewItem.Text = (i + 1).ToString();
listviewItem.SubItems.Add(arr[0]);
listviewItem.SubItems.Add(arr[1]);
listviewItem.SubItems.Add(arr[2]);
listView1.Items.Add(listviewItem);
}
}
}
写txt
private void button3_Click_1(object sender, EventArgs e)
{
//将listView中的内容保存成TXT格式
string[] arr = new string[listView1.Items.Count];
for (int i = 0; i < listView1.Items.Count; i++)
{
string s = "";
int len = listView1.Items[0].SubItems.Count;
for (int j = 1; j < len; j++)
{
//用逗号作为分割符 如果 有子项中包含逗号 要出问题的
s += listView1.Items[i].SubItems[j].Text + ",";
}
if (s.EndsWith(","))
s = s.Substring(0, s.Length - 1);
arr[i] = s;
}
//保存到文件
File.WriteAllLines(conf, arr);
}
边栏推荐
- The jdbcurl is configured correctly in the project, but the jdbcurl is the wrong path after the project is started
- Applet vant UI implementation calls interface data and displays it
- SQL server changes the primary key index to a non clustered index
- JSON使用示例
- Submit values of various inputs of the form
- AutoCAD 2020.3 Chinese Version (old version)
- Example of using listagg in Oracle 11g (splicing the values of a field into a line, separated by commas)
- 什么是分布式事务
- Ugui text spacing textspacing
- CollectionViewCell
猜你喜欢

【Oracle 数据库】奶妈式教程 day11 数值函数
![[普通物理]波的能量与干涉](/img/fe/066aa9e8ed776b8f069b59b7123367.png)
[普通物理]波的能量与干涉

OSI and tcp/ip

Use js to download the current image

SQL server changes the primary key index to a non clustered index

MySQL master-slave replication

Upload your own library to pod

MySQL 8.0 under Linux forgets the password

Model electricity experiment -- Experiment 2 JFET common source amplifier circuit

Energy and interference of waves
随机推荐
模板代码概述
Download addresses of Xcode versions
lr 2022超详细安装教程「最新」
Concatenate the specified character at the end of a number in a string
The significance of code coverage testing to programming white and its application
先锋期货安全么?期货开户都是哪些流程?期货手续费怎么降低?
面试突击59:一个表中可以有多个自增列吗?
Docker install mysql, hello world
【Oracle 数据库】奶妈式教程 day14 转换函数
Some problems caused by null data in MySQL
Oracle execution plan analysis
Node red sends wechat official account message (template message)
mysql查询group by 1055 问题完美解决,最简单最便捷的方法
【Oracle 數據庫】奶媽式教程 day13 日期函數
navicat如何查询已连接的数据库密码信息
How to create an index
0基础自学stm32(野火)——什么是寄存器?
Detailed explanation of subnet mask
What are uniapp, wap2app and 5 + app in dccloud?
Asynchronous sending and receiving of message passing based concurrent programming (MPI)