1

In a C# ListView with View=List, there is empty space at the bottom, reserved for a scrollbar. Weirdly, setting Scrollable=false will only increase the size of this unused space.

How can I get rid of this space or make sure it's used to display items?

Edit: I'm having this issue in a Windows Form Application.

Edit 2: The issue seems to be coupled with the font size somehow. I need the font size to be 9 pt. With 11 pt this problem doesn't appear.

Edit 3: I also tried Item spacing in ListView where View=List but that didn't help either.

Edit 4: It happens under Win7 with the Win7 Theme. However, at least with Scrollable = false, it doesn't happen with the Classic Theme.

Unused space at the bottom of ListView, View=List

Community
  • 1
  • 1
Simeon
  • 408
  • 1
  • 7
  • 17
  • This might help http://stackoverflow.com/questions/1561780/wpf-listview-scrollbar-visible-to-false – Connell.O'Donnell Apr 23 '17 at 21:31
  • 2
    How would a WPF solution help?? - This is really weird. I never use List mode but still.. - Looks a little as if it tries to fit in 12 items with 11pt font. Makes no sense.. – TaW Apr 23 '17 at 22:28
  • I think you're on to something. The problem appears with a 9pt font. If I change it to 11, the space is gone! Seems almost like the listView has some internal reference height to calculate the number of items that fit into one column and it doesn't get updated properly when the font size is changed. – Simeon Apr 24 '17 at 08:20
  • Yes, or it has some not so clever ideas about dpi-awareness or rather lack of it.. – TaW Apr 24 '17 at 11:56
  • I wonder if @Hans Passant can help us out here..? - Btw: The question is __neither__ unclear __nor__ lacking code. – TaW Apr 24 '17 at 18:15

1 Answers1

0

Still hoping for a more elegant solution, but for now, I found this workaround:

One can use a Panel to get rid of the extra space. I got the idea from TaW's answer to Add padding to last ListView item in WinForms

Remember, this worked for me, because I don't want or need a Scrollbar.

        listView1.Scrollable = true;
        int itemHeight = listView1.GetItemRect(0).Height;
        int numItemsPerColumn = 10;
        //One needs to add 21 to the height, because even if no Scrollbar
        //is needed, that space will stay reserved.
        listView1.Size = new Size(500, itemHeight * numItemsPerColumn + 21);
        Panel P = new Panel();
        P.BackColor = listView1.BackColor;
        P.Location = listView1.Location;
        //The height you actually want
        P.Size = new Size(500, itemHeight * numItemsPerColumn + 4);
        P.BorderStyle = listView1.BorderStyle;
        listView1.BorderStyle = BorderStyle.None;
        listView1.Parent = P;
        listView1.Location = new Point(0, 0);
        this.Controls.Add(P);
Community
  • 1
  • 1
Simeon
  • 408
  • 1
  • 7
  • 17