如何在“详细信息"视图中设置列表视图的“可点击"字段 [英] How to set a List View's Click-able field in Details view

查看:96
本文介绍了如何在“详细信息"视图中设置列表视图的“可点击"字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近几天,我一直在尝试使用列表视图控件,但是在控制列表视图的详细信息视图中的可点击字段时遇到了麻烦.问题是我有人员名单:名字,姓氏和唯一的ID号.当我将记录添加到列表视图时,我知道列表视图项是可单击字段,而不是子项,而是如何控制将项添加到哪一列.

为了更好地说明,这些列按ID,Last Name,First Name的顺序排列.我正在尝试将该项目添加到姓氏"列中,并将其设置为可点击的字段.

我知道这可能与列的显示索引有关,但是当您在设计时添加它们时,列本身也有某种索引.如果有人也可以解释它们之间的区别,那么这可能会帮助我了解更多信息.

任何帮助,我们将不胜感激. :)

I have been trying out List View controls these past few days and I am having trouble controlling the click-able field in the details view of the list view. The issue is that I have list of people: first name, last name and a unique ID number. When I add the records to the list view I understand that the list view item is the click-able field not the sub-items but how can you control which column the item is added under.

To explain a little better the columns are in the order of ID, Last Name, First Name. I''m trying to add the item to the last name column and make this the click-able field.

I understand this might have something to do with the display index of the columns but there is also some kind of index beside the columns themselves as well when you add them at design time. If anyone could explain the difference between these as well this might help me understand a little more.

Any help is most appreciated. :)

推荐答案

我相信您可能需要根据列的宽度来计算单击时所在的列.我不认为listview是一个网格,但有网格控件.我认为它只知道您单击了哪一行.
I believe you may need to calculate which column you are over in your click based on the width of the columns. I don''t think the listview is a grid, there are grid controls for that. I think it just knows what row you clicked.


听起来您在问两个问题.第一个是如何将SubItems添加到ListView.这里是一些示例代码,用于使用以下字段设置新的ListViewItem:日期,时间,姓氏,名字.请注意,我没有时间,所以我将其留空了……但是您仍然必须添加一些内容.

It sounds like you''re asking two questions. The first is how to add SubItems to a ListView. Here''s some sample code to set up a new ListViewItem with the following fields: Date, Time, LastName, FirstName. Notice that I didn''t have the time, so I left it blank...but you still have to add something.

ListViewItem item1 = new ListViewItem("3/25/2010");
item1.SubItems.Add("");
item1.SubItems.Add("Jeffers");
item1.SubItems.Add("William");
listView1.Items.Add(item1);



至于根据特定列对项目进行排序...在这里可以看到:如何在Visual中按列对ListView控件进行排序C# [^ ]

同样重要的是要注意,尽管ListViewItem具有SubItems,但第一个SubItem实际上是第一列的值.因此,如果要按设置的顺序使用姓氏,则需要SubItems[1].



As far as sorting the items based on a specific column...have a look here: How to sort a ListView control by a column in Visual C#[^]

It''s also important to note that while the ListViewItem has SubItems, the first SubItem is actually the first column''s value. So, if you want LastName by the order you set, you would need SubItems[1].


这篇关于如何在“详细信息"视图中设置列表视图的“可点击"字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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