Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable height rows in WinForms ListView

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.

like image 930
dbkk Avatar asked Mar 09 '09 12:03

dbkk


5 Answers

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".

like image 153
Marc Gravell Avatar answered Nov 07 '22 11:11

Marc Gravell


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.

like image 36
lakshmanaraj Avatar answered Nov 07 '22 13:11

lakshmanaraj


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.

like image 2
Grammarian Avatar answered Nov 07 '22 13:11

Grammarian


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.

like image 1
Chris Thompson Avatar answered Nov 07 '22 11:11

Chris Thompson


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):

enter image description here

like image 1
Libor Avatar answered Nov 07 '22 12:11

Libor