Icemanind
Icemanind

Reputation: 48686

Getting graphical Point of Listview items

I have a ListView control on my form and I am trying to get either a Point or even better, a Rectangle of each visible item in my ListView. Anyone know of a trick to do this?

Upvotes: 1

Views: 277

Answers (2)

John Alexiou
John Alexiou

Reputation: 29244

What I have done is handle the ListView.DrawSubItem event, which gives me access to a DrawListViewSubItemEventArgs e instance with a e.Bounds property giving me the rectangle you are asking for.

If you don't want to do any drawing on your own just set e.DrawDefault = true;

Here is an example of the results: ListView DrawSubItem

Upvotes: 1

zmilojko
zmilojko

Reputation: 2135

        foreach (ListViewItem item in myListView.Items)
        {
            Rectangle result = item.Bounds;
            if(result.IntersectsWith(myListView.ClientRectangle))
            {
                //there you go
            }
        }

More about the Bounds you can find here.

Upvotes: 2

Related Questions