问题描述
我在我的项目中使用 objectlistview,在构造函数中我有这样的代码:
foreach (OLVColumn item in olv.AllColumns)
{
item.Width = -2;
var headerstyle = new HeaderFormatStyle();
headerstyle.SetFont(new Font(new FontFamily("Segoe UI"),12.0f,FontStyle.Bold));
headerstyle.SetBackColor(Color.FromArgb(16,16,16));
headerstyle.SetForeColor(Color.White);
item.HeaderFormatStyle = headerstyle;
}
此代码为我的行提供了漂亮的背景色并设置了默认值。这有效,结果是这样的:
但是在标题行的末尾有这个:
与白色(默认)背景色有一个小的差距。我可以通过使类别列的大小变大来解决此问题,但允许用户隐藏和更改列的宽度,因此这不会解决我的问题。我怎样才能到达代码中的那个白点? 我已检查 http://objectlistview.sourceforge.net/cs/recipes.html#how-do-i-change-the-font-or-color-of-the-column-headers,但找不到解决方案。
解决方法
通过将属性 FillsFreeSpace
设置为 true
,可以使列自动填充可用的水平空间。
如果不想让主列之一拉伸到总宽度,则可以将 FillsFreeSpace
设置为 true 的虚拟列(带有空标题文本)作为最后一列插入。可能建议将该列的 Hideable
和 IsEditable
设置为 false
。