1

How can I add some extra space between the last item in a listview and the bottom of the control? I don't want to add an empty item to the bottom of the list.

admdrew
  • 3,790
  • 4
  • 27
  • 39
JochenDB
  • 588
  • 10
  • 31
  • Maybe this will help ? http://qdevblog.blogspot.nl/2011/11/c-listview-item-spacing.html – Sybren Oct 22 '14 at 18:25
  • When you add a new item to the ListView you can just add to the upper bounds of the item such as: myListViewItem.Bounds.Top += marginAmt; You can place this within the ControlAdded event of the ListView. – Ckrempp Oct 22 '14 at 18:44
  • What View mode do you use? – TaW Oct 22 '14 at 21:47
  • @Ckrempp: This i s Winforms. The Bounds can't be changed and adding an Item doesn't invoke ControlAdded.. – TaW Oct 26 '14 at 11:05
  • @Sybren: Intersting, but only works for the LV as a whole, not individual Items. – TaW Oct 26 '14 at 11:07

2 Answers2

4

You can't do this directly. Unfortunately the styling options of ListView are rather limited.

Unless you go for owner-drawing it.. Which is powerful and not very hard. But even there I doubt that the Items can have different Heights..

But there is a simple trick you can use:

Remove the LV's borders and place it inside a Panel with appropriate borders. Dock it there to Fill the Panel and give the Panel a Padding of maybe (0;0;0,10) and voila, the will always be a Padding of 10 pixels that looks as if it belongs to the ListView..

Instead of using the Designer, you could put these lines in the Form.Load to make it work on startup:

Panel P = new Panel();
P.BackColor = listView1.BackColor;
P.Location = listView1.Location;
P.Size = listView1.Size;
P.Padding = new System.Windows.Forms.Padding(0,0,0,10);
P.BorderStyle = listView1.BorderStyle;
listView1.BorderStyle = BorderStyle.None;
listView1.Parent = P;
listView1.Dock = DockStyle.Fill;
this.Controls.Add(P);
TaW
  • 53,122
  • 8
  • 69
  • 111
0

Use item.IndentCount

Microsoft ListViewItem property IndentCount

enter image description hereCount]2

Edson Marcio
  • 26
  • 1
  • 3