C#ListViewItemCollection不包含Count的定义

Bri*_*hon 1 c# listview count

在C#中,我有一个ListView控件,想要获取控件项集合中当前项的计数,但下面的代码会产生错误:

'System.Windows.Forms.ListView.ListViewItemCollection'不包含'Count'的定义,并且没有扩展方法'Count'接受类型'System.Windows.Forms.ListView.ListViewItemCollection'的第一个参数可以找到(你是吗?)缺少using指令或程序集引用?)

ListView.ListViewItemCollection lvitems = lvDropSummary.Items;
int iLVItemsCount = lvitems.Count();
Run Code Online (Sandbox Code Playgroud)

我没有看到特定的代码示例在列表视图中获取所有项的计数,但根据文档(和intellisense),该属性存在:

http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.listviewitemcollection.count(v=vs.100).aspx

Met*_*Man 5

你试图像一个方法一样使用

int iLVItemsCount = lvitems.Count();

将其更改为以下应该可行

 int iLVItemsCount = lvitems.Count;
Run Code Online (Sandbox Code Playgroud)