views:

3073

answers:

6

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.

+2  A: 

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

Marc Gravell
I tried the GridView, but for some reason it is *much* slower (in VirtualMode with many items).
dbkk
+1  A: 

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

To override the item height individullay, then grasp the concept of

http://objectlistview.sourceforge.net/cs/features.html

lakshmanaraj
That is good as a one-off solution (if height is known already), but I'd like it to adjust to long multi-line cells.
dbkk
added another answer got from sourceforge..
lakshmanaraj
Thanks, the sourceforge one looks useful.
dbkk
A: 

The Windows ListView control itself (which is wrapped by the .NET ListView control) doesn't support variable row heights.

If you stick with the ListView, you'll need to have fixed height rows.

Bevan
A: 

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.

Chris Thompson
If it isn't possible to use the DataGridView, then this seems like your only option.
cofiem
This is for ListBox, not ListView. A different control, that doesn't support MVC / virtual mode.
dbkk
He didn't specify that he needed virtual mode, so I was just suggesting an alternate control that would meet the needs.
Chris Thompson
A: 

If variable height rows are what you want, I'd consider using the DataGridView instead. It very much supports variable height rows (through the use of cell styles) and is much easier to use than trying to shoehorn the list view into doing what you want.

Ken Wootton
Already suggested in first comment...
dbkk
+1  A: 

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.

Grammarian