2017-04-23 56 views
0

在带有View = List的C#ListView中,底部有空白区域,为滚动条保留。奇怪的是,设置Scrollable = false只会增加这个未使用空间的大小。C#ListView,View = List - 如何摆脱底部未使用的空间?

我该如何摆脱这个空间或确保它用来显示物品?

编辑: 我在Windows窗体应用程序中遇到此问题。

编辑2:该问题似乎与某种程度上的字体大小相结合。我需要的字体大小是9磅。用11磅这个问题不会出现。我也尝试过Item spacing in ListView where View=List,但这也没有帮助。

编辑4:它发生在Win7下的Win7主题。但是,至少在Scrollable = false的情况下,经典主题不会发生这种情况。

Unused space at the bottom of ListView, View=List

+0

这可能有助于http://stackoverflow.com/questions/1561780/wpf-listview-scrollbar-visible-to-false –

+2

如何将一个WPF解决方案的帮助? - 这真的很奇怪。我从来没有使用列表模式,但仍然.. - 看起来有点像它试图适应12个11pt字体的项目。没有意义.. – TaW

+0

我认为你是在做某件事。问题出现在9pt字体中。如果我将其更改为11,则空间不见了!看起来几乎像listView有一些内部参考高度来计算适合一列的项目的数量,并且当字体大小改变时它不会被正确更新。 – Simeon

回答

0

仍然希望一个更优雅的解决方案,但现在,我发现这个解决办法:

可以使用一个面板摆脱多余的空间。我从TaW的答案中得到了这个想法Add padding to last ListView item in WinForms

请记住,这对我很有用,因为我不需要或不需要滚动条。

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