none
Scrollable ownerdrawn listview with an image RRS feed

  • Question

  • I have a class derived from ListView that I am doing custom drawing on. Basically I have my list and then at the bottom of the list I want to draw an image. The list is being used to show information about an item and there is an image associated with that item. 

    The custom drawing is fine I have the image drawing properly at the location I need and it looks fine. The issue I am having is that I can't figure out how to expand the bounds of the control so that when the vertical scrollbars show up it they will include the image in the scroll.

    I have tried several things already including...

    -pInvoke with SetScrollRange on SB_VERT. The problem is something resets my range to exclude the image. 

    -Adding my own VScrollbar and then using pInvoke so that whenever that scrollbar changes value I set the value of SB_VERT and basically just bind the two scrollbars together only with my updated Maximum range. It seems like if I call SetScrollPos and SetScrollRange and then PostMessage with WM_SCROLL the control doesn't control.

    -After drawing my image set the ListView.Bounds to include the size of the image. This one seems flaky but it might be that I was doing this wrong. But when the Bounds are changed it appeared to call DrawItem again.

    -Adding a PictureBox control to my ListView programatically and then assigning the image to that picturebox. It seems like when the ListView is calculating its size it ignores the PictureBox although this might be due to the fact that I can't assign the size of the PictureBox until I draw the Image (they are different sizes).

    Again all I am trying to do is draw 1 image at the bottom of my listview (which works) and then also ensure when the user resizes the control that the scrollbars take the image dimensions into account. So scrolling to vertical max would scroll to the bottom of the image not to the bottom of the list items (which is what happens now)

    The relevant drawing code is as pasted below

    privatevoid LookupListView_DrawItem(object sender, DrawListViewItemEventArgs e) { e.DrawDefault = true; if(e.ItemIndex == Items.Count - 1 && mImage != null)  { float lLineSpacingPixels = Font.Size *  Font.FontFamily.GetLineSpacing(FontStyle.Regular) / Font.FontFamily.GetEmHeight(FontStyle.Regular); e.Graphics.DrawImage(mImage, Items[Items.Count - 1].Position.X, Items[Items.Count - 1].Position.Y + (lLineSpacingPixels * 2));

    } }

    • Moved by CoolDadTx Thursday, September 18, 2014 1:49 PM Winforms related
    Thursday, September 18, 2014 1:36 PM

Answers

All replies

  • Hi Hyperpred,

    Try to use this, http://www.codeproject.com/Articles/9188/Embedding-Controls-in-a-ListView

    you could embed a sized picture box  in the listviewitem.

    • Marked as answer by Hyperpred Friday, September 19, 2014 1:43 PM
    Friday, September 19, 2014 11:47 AM
  • Thank you Omar, the link was a bit more straight forward than what I was doing though it didn't solve my problem where the scrollbar seems to ignore that the control is embedded. I'm going to mark as the answer because it definitely helped me clean up other area's. But, I don't think I'll be able to fully account for scrolling in a listview with a variable sized image being placed in it.

    Thanks!

    Jarrett

    Friday, September 19, 2014 1:43 PM