I want to change the Item's/Row's height in listview.
I searched every where and I figured that in order to change the height I need to use LBS_OWNERDRAWFIXED
or MeasureItem
or something like that.
The problem is that I dont know exactly what to do and how to use it..
Can anyone help me with it?
Edit:
I cant use the ImageList hack because I am using the SmallImageList for real and I need different line height from the ImageList images size.
Thanks!
For the people that are still struggling with this, here is the code I use:
private void SetHeight(ListView listView, int height) { ImageList imgList = new ImageList(); imgList.ImageSize = new Size(1, height); listView.SmallImageList = imgList; }
To use this, just do:
SetHeight(lvConnections, 25);
It can be done using the SmallImageList
trick -- you just have to be careful. ObjectListView -- an open source wrapper around a standard .NET ListView
-- uses that trick to successfully implement a RowHeight
property.
If you want 32 pixels for each row, allocate an ImageList
that is 16x32 (width x height), and then position each of your images in the vertical middle of the 32-pixel height.
This screen shot shows 32-pixel rows and the word wrapping that is possible because of the extra space:
ObjectListView
does all this work for you. In fact, if you are trying to do anything with a ListView, you should seriously looked at using an ObjectListView
instead. It makes many difficult things (e.g. sorting by column type, custom tooltips) trivial, and several impossible things (e.g. overlays, groups on virtual lists) possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With