views:

35

answers:

2

How can we get Number of rows Present in Listview?

+1  A: 

Couldn't you just use ListView.Items.Count?

Andy
It can't work...
atul gupta
@atul What problem are you seeing? Without more information, it's hard to provide alternative that would work for you.
Andy
Sorry Andy I Forgot to tell that i m working in MVVM Pattern, i hv to count rows of Listview in ViewModel. well in MVVM Pattern Viewmodel Doesn't know about view then hw can i use Listview.Items.Count????
atul gupta
What about @Kevin's suggestion to use the count of the collection bound to the control?
Andy
+1  A: 

Well, you see. When you bind a list view to some sort of collection (preferably some sort of observable collection) with some sort of type. You can add/remove.

But you also have the functionality to say observablecollection.count.

Now if you are adding the items inside the XAML. a quick and easy way to access it is.

x:Name="name of the list" then in the code behind say (name of the list).count.

That should give you access within the code behind, or if you don't want to do it in the code behind. You will need some sort of window dictionary.

and you can access the (name of the list) through your dictionary.

Kevin
By the way, if you are using the model-view-viewmodel practice. in which i use. You should bind your list view to some sort of observable collection.
Kevin