填充列表视图多列 [英] Populating a listview multi-column

查看:34
本文介绍了填充列表视图多列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于 Listbox 到 ListView 的迁移.

Regarding Listbox to ListView migration.

你好.

我有一个列表框,我将这样的条目添加到:

I have a Listbox I add entries like this to:

1;内容

其中 1 始终是 int 而 content 始终是字符串.我可以单独访问每个.

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

现在我想对结果进行降序排序,即:

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

1;content
4;content2
2;content3

=>

4;content2
2;content3
1;content

由于这看起来不太好,我想改用 Listview.像这样:

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

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

问题是,表格属性似乎不存在,所有条目都像符号一样放入资源管理器的列表视图中.我也有问题到达"第二列(内容),即我只看到 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.

我将如何为此准备和填充 c# .net 4 中的列表视图?

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

推荐答案

将ListView设置为Details模式:

To set the ListView into Details mode:

        listView1.View = View.Details;

然后设置你的两列:

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

然后添加您的项目:

        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 构造函数的重载,该构造函数采用表示列值的字符串数组.但是有 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.

设置项目的自动排序:

        listView1.Sorting = SortOrder.Descending;

这篇关于填充列表视图多列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆