Diego Alves Do Carmo
Diego Alves Do Carmo

Reputation: 57

Best way to check if listview is empty?

Believe it or not I searched on google but I was not able to find how to see if a listview is empty. I want to hide some controls if so. I tried lv.items.count but it always returns 0. Whether or not the control is empty.

Upvotes: 2

Views: 13648

Answers (2)

Bill Gregg
Bill Gregg

Reputation: 7147

Icarus is right about the order of binding mattering, but I'd like to point out that lv.Items.Any() is a more efficient way of seeing if there are any items to display. No sense in counting the whole list if you just want to know if at least 1 thing is in it.

Upvotes: 3

Icarus
Icarus

Reputation: 63970

lv.Items.Count would return 0 only if you check before you bind the data. If you check after you bind the data, it returns the number of rows.

Upvotes: 5

Related Questions