填充一个ListView多列ListView

2023-09-03 03:01:38 作者:¢虛僞小男仒

对于列表框的ListView迁移。

Regarding Listbox to ListView migration.

您好。

我有一个列表框我添加条目像这样:

I have a Listbox I add entries like this to:

1;含量

其中,1始终是一个int和内容始终是一个字符串。我可以访问每一个分开。

Where 1 is always an int and content is always a string. I can access each one seperately.

现在我想要的结果被descendingly排序,即:

Now I want the result to be sorted descendingly, ie:

1;content
4;content2
2;content3

=>

4;content2
2;content3
1;content

由于这并不好看,我想用一个列表视图来代替。像这样的:

As this doesn't look good, I want to use a Listview instead. Like this:

Frequency | Content
===============
4 | content2
2 | content3
1 | content

但问题是,在表格的属性似乎并不存在,所有的项目都正在实施类似的符号在浏览器列表视图。我也有问题,达的第2列(内容),也就是我只看到4,2,1。

Problem is, the tabular property does not seem to exist, all entries are being put in like symbols in a listview in explorer. Also I have problems "reaching" the 2nd column(content), ie I only see 4,2,1.

我将如何prepare和填充在C#.NET 4一个ListView是什么?

How would I prepare and populate a listview in c# .net 4 for that?

推荐答案

要设置的ListView进入详情模式:

To set the ListView into Details mode:

        listView1.View = View.Details;

然后设置你的两列:

Then to set up your two columns:

        listView1.Columns.Add("Frequency");
        listView1.Columns.Add("Content");

然后添加你的项目:

Then to add your items:

        listView1.Items.Add(new ListViewItem(new string[]{"1", "content"}));
        listView1.Items.Add(new ListViewItem(new string[]{"4", "content2"}));
        listView1.Items.Add(new ListViewItem(new string[]{"2", "content3"}));

我选择使用ListViewItem的构造函数的字符串数组重新presenting列值的过载。但也有22超载!翻阅然后,找到最适合您的情况之一。

I chose to use the overload of the ListViewItem constructor that takes a string array representing the column values. But there are 22 overloads! Look through then and find the one that fits your situation best.

要设置项目的自动分拣:

To set automatic sorting of items:

        listView1.Sorting = SortOrder.Descending;
 
精彩推荐
图片推荐