C# ListView SelectedIndices 和 SelectedItems 计数问题

发布于 2024-12-14 15:40:31 字数 815 浏览 1 评论 0原文

在使用新的 winform 项目的 C# 2010 Express 上使用这些方法时遇到一些问题,两种数据类型都有方法计数,这似乎记录在 MSDN 上,但我似乎无法让它们工作。编译时列表视图控件本身看起来很好。

 listView2.SelectedItems.Count();

错误 1“System.Windows.Forms.ListView.SelectedListViewItemCollection” 不包含“Count”的定义并且没有扩展方法 “Count”接受类型的第一个参数 'System.Windows.Forms.ListView.SelectedListViewItemCollection' 可以 被发现(您是否缺少 using 指令或程序集引用?)

listView2.SelectedIndices.Count();

错误 1“System.Windows.Forms.ListView.SelectedIndexCollection”确实如此 不包含“Count”的定义,并且没有扩展方法“Count” 接受类型的第一个参数 可以找到“System.Windows.Forms.ListView.SelectedIndexCollection” (您是否缺少 using 指令或程序集引用?)

这两种数据类型似乎都已定义。也不能使用索引。

 listView2.SelectedItems[0] 

Having some trouble with these methods on C# 2010 express with a new winform project both data types have the method count, which seems to be documented on MSDN, however I can not seem to get them to work. The listview control itself seems fine when compiling.

 listView2.SelectedItems.Count();

Error 1 'System.Windows.Forms.ListView.SelectedListViewItemCollection'
does not contain a definition for 'Count' and no extension method
'Count' accepting a first argument of type
'System.Windows.Forms.ListView.SelectedListViewItemCollection' could
be found (are you missing a using directive or an assembly reference?)

listView2.SelectedIndices.Count();

Error 1 'System.Windows.Forms.ListView.SelectedIndexCollection' does
not contain a definition for 'Count' and no extension method 'Count'
accepting a first argument of type
'System.Windows.Forms.ListView.SelectedIndexCollection' could be found
(are you missing a using directive or an assembly reference?)

Both data types seem to be defined. Also cannot use indices.

 listView2.SelectedItems[0] 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撩人痒 2024-12-21 15:40:41

您发出调用就好像它是一种方法一样。您只是尝试访问列表的 Count 属性。删除 Count 调用末尾的 ()。

You're issuing the call as if it were a method. You're just trying to access the Count property of the list. Remove the () at the end of your Count call.

终弃我 2024-12-21 15:40:39

它们是属性,而不是方法:

http:// msdn.microsoft.com/en-us/library/system.windows.forms.listview.selectedlistviewitemcollection.aspx

http://msdn.microsoft.com/en-us /library/system.windows.forms.listview.selectedindexcollection.aspx

删除括号:

var count = listView2.SelectedItems.Count;
count = listView2.SelectedIndices.Count;

您可以在它们上使用索引表示法。 SelectedItems 属性公开 stringint 索引。 SelectedIndices 属性仅公开 int 索引。

They are properties, not methods:

http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.selectedlistviewitemcollection.aspx

http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.selectedindexcollection.aspx

Remove the brackets:

var count = listView2.SelectedItems.Count;
count = listView2.SelectedIndices.Count;

You can use index notation on them. The SelectedItems property exposes a string and int index. The SelectedIndices property only exposes an int index.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文