English 中文(简体)
名单
原标题:ListView Columns

页: 1 我的“C:档案”。

1;aaa 
2;bbb
3;ccc 
4;ddd 

and so on. (each number and text in separate line) My code:

FileStream spis = File.Open("C:\file.txt", FileMode.Open, FileAccess.Read);
StreamReader yaRead = new StreamReader(spis);
string yaView = yaRead.ReadToEnd();
yaRead.Close();
spis.Close();
String[] yaArray = yaView.Split(new char[] { ; });
foreach (string ya in yaArray)
{
    listView1.Items.Add(ya);
}

成果

1
aaa
bbb
(...)

页: 1 请帮助我确定这一点。

最佳回答

页: 1 清单:

最简单的办法是:

ListViewItem newItem = new ListViewItem("1");
newItem.SubItems.Add("aaa");
listView1.Items.Add(newItem);

If we take your example, we can simply do something like the following:

string[] yaArray = yaView.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); 

这将使你看到一个阵列:

[1;aaa]
[2;bbb]
[3;ccc]
[4;ddd]

我们根据新界线而不是半殖民地分裂。

接着,它只是做以下事情:

foreach(string lineItem in yaArray)
{
  string[] listViewRow = lineItem.Split(new string[] { ";" }, StringSplitOptions.None); //Now we split on the semi colon to give us each item
  ListViewItem newItem = new ListViewItem(listViewRow[0]);
  newItem.SubItems.Add(listViewRow[1];
  listView1.Items.Add(newItem);
}

这应当给你想要的东西。

问题回答

请列入SUB项目。

foreach(var line in File.ReadAllLines(@"C:file.txt"))
{
  listView1.Items.Add(line.Split( ; ));
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签