C# ListView SelectedIndices 和 SelectedItems 计数问题
在使用新的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您发出调用就好像它是一种方法一样。您只是尝试访问列表的 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.
它们是属性,而不是方法:
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
删除括号:
您可以在它们上使用索引表示法。
SelectedItems
属性公开string
和int
索引。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:
You can use index notation on them. The
SelectedItems
property exposes astring
andint
index. TheSelectedIndices
property only exposes anint
index.