【问题标题】:How to resize rows in a datagridview so that they fill the entire control and all have the same height如何调整datagridview中的行大小,以使它们填充整个控件并且都具有相同的高度
【发布时间】:2016-01-12 20:45:11
【问题描述】:

我目前在一个事件管理应用程序中工作。

到目前为止,我已经使用了DataGridView 控件来显示月历:

但是表格行的大小不合适。

我想实现如下图所示:

注意六行的高度是相同的,如果调整网格大小,比例保持不变。

我尝试通过DataGridView.AutoResizeRows 实现这一目标。它没有用。 有解决办法吗?

【问题讨论】:

  • @TaW 当我写代码时,您似乎在我回答之前发表了您的评论:) 我删除了我的答案。随意张贴你的答案,你有我的投票:)
  • @Reza:不,不要删除它;它更完整,独立存在..!
  • @TaW 谢谢你的好意。我取消了答案。

标签: c# winforms datagridview


【解决方案1】:

DataGridViewScrollBars 属性设置为None 并使用此代码设置行的大小:

foreach (DataGridViewRow row in dataGridView1.Rows)
{
    row.Height = (dataGridView1.ClientRectangle.Height - dataGridView1.ColumnHeadersHeight) / dataGridView1.Rows.Count;
}

也使用此代码来处理大小调整:

private void dataGridView1_SizeChanged(object sender, EventArgs e)
{
    foreach (DataGridViewRow row in dataGridView1.Rows)
    {
        row.Height = (dataGridView1.ClientRectangle.Height - dataGridView1.ColumnHeadersHeight) / dataGridView1.Rows.Count;
    }
}

【讨论】:

  • 谢谢!它有效,但前提是 AutoSizeRowsMo​​de 的值为 None。
  • 不客气 :) AutoSizeRowsMode 的默认值是None 所以我没有提到。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-05-15
  • 2021-05-19
  • 1970-01-01
  • 2011-10-31
  • 2012-02-06
  • 2021-07-16
  • 1970-01-01
相关资源
最近更新 更多