Is it possible to have variable-height rows within a WinForms ListView in Details mode?
There is no RowHeight or Rows[i].Height property on the control as far as I know.
Some blogs suggests implementing OwnerDraw, which I did, but I still can't find anything resembling height property from within the event handlers.
Ideally, the row height would auto-size to show multiline text when needed.
If you are using details mode, I wonder if DataGridView
wouldn't be more versatile. Each row has a Height, or you can use AutoSizeRowsMode to do it automatically. See MSDN "Resizing Columns and Rows in the Windows Forms DataGridView Control".
One option to think of:
To override the item height of all rows, create a dummy ImageList and set it to the desired height and assign it to the listview depending on the view or grasp the concept of http://www.codeproject.com/KB/list/changerowheight.aspx
If you use ObjectListView, you can change the item height of all rows pretty easily. But still, there is no way to change the individual item height as long as you are using ListView.
The ObjectListView mentioned in the first answer does not support variable row heights. It says this clearly in its FAQ. The underlying Windows listview control simply does not support variable row height. You have to look to other, custom written controls.
You may want to consider Matthew Hall’s excellent XPTable and its update project, as well as Lee Paul Alexander’s fantastic Outlook-style list.
The ListBox control does support variable height rows, but you have do all the drawing yourself.
Set the DrawMode to OwnerDrawVariable
Then add
protected override void OnDrawItem(DrawItemEventArgs e)
{
/* Drawing code here */
}
protected override void OnMeasureItem(MeasureItemEventArgs e)
{
/* Measure code here */
}
I use an owner-drawn listbox in a program called Task Reporter to list each task the user entered. Each entry is differently depending on how much text is entered.
If you are OK with 3rd party components, Better ListView supports exactly this (each item has a CustomHeight
property so each can have different height):
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