使DataGridView SingleVertical CellBorderStyle一直向下延伸?

时间:2012-04-28 14:04:26

标签: .net winforms datagridview datagridviewcellstyle

在我开始之前注意..这是客户想要它的样子,所以如果有人有“那可怕的UI /风格/外观/等”,我可能会或可能不同意,但这是他们想要的。意见表示赞赏,但这是他们的要求。 :)

我有一个DataGridView,我已将SingleVertical CellBorderStyle应用于。我试图让垂直列分隔线一直向下到控件的末尾,而不是在最后一个单元格结束。有没有办法做到这一点,而不必重写OnPaint或类似的东西?

1 个答案:

答案 0 :(得分:0)

由于你已经拥有SingleVertical CellBorderStyle,你可以用一个空白的最后一行填充剩余空间:

//calculate the space already filled by column headers and rows
int currentContentHeight = Grid.ColumnHeadersHeight;
for (int i = 0; i < Grid.Rows.Count; i++)
{
    currentContentHeight += Grid.Rows[i].Height;
}
//then calculate the space remaining
int remainingHeightToEndOfControl = Grid.Height - currentContentHeight;
//then fill it with one big blank final row:
if (remainingHeightToEndOfControl > 0)
{
    Grid.Rows.Add();
    Grid.Rows[Grid.Rows.Count - 1].Height = remainingHeightToEndOfControl;
}

您可能需要从剩余的高度中扣除2分左右才能占用控制边界。