c# listview 导入txt 加序号
我有一段数据
123-123
456-456
789-789
用openfiledialog导入listview,需要分割,
然后在前面加一栏序号,怎么实现啊
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; namespace WindowsFormsApplication22 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { int couns=0; listView1.View = View.Details; ColumnHeader ch1 = new ColumnHeader(); ch1.Text = "序号"; ColumnHeader ch2=new ColumnHeader(); ch2.Text = "账号"; ColumnHeader ch3=new ColumnHeader(); ch3.Text = "密码"; listView1.Columns.Add(ch1); listView1.Columns.Add(ch2); listView1.Columns.Add(ch3); OpenFileDialog file = new OpenFileDialog(); if (file.ShowDialog() == DialogResult.OK) { FileStream fs=new FileStream(file.FileName,FileMode.Open); StreamReader sr = new StreamReader(fs); sr.BaseStream.Seek(0, SeekOrigin.Begin); while (!sr.EndOfStream) { string[] ss = sr.ReadLine().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries); if (ss.Length == 2) { couns++; string[] sss = new string[3] { couns.ToString(), ss[0], ss[1] }; ListViewItem lvi = new ListViewItem(sss); listView1.Items.Add(lvi); } } } } } }