如何调整datagridview中的行大小,以便它们填充整个控件,并且都具有相同的高度 [英] How to resize rows in a datagridview so that they fill the entire control and all have the same height
问题描述
我正在一个事件管理应用程序。
I am currently working at an events management application.
到目前为止,我已经使用了一个 DataGridView
控件显示每月日历:
So far I have used a DataGridView
control to display a monthly calendar:
但是表行的大小不正确。
But the table rows are not properly sized.
我想实现像下面的照片:
I would like to achieve something like in the photo below:
请注意,六行的高度相同,如果网格调整大小,则比例将保持不变。
Notice that the heights of the six rows are the same and the proportion is maintained if the grid is resized.
我试图通过 DataGridView.AutoResizeRows
实现。它没有工作。
是否有解决方案?
I tried to achieve that with DataGridView.AutoResizeRows
. It didn't work.
Is there a solution?
推荐答案
设置 ScrollBars
DataGridView
到无
的属性,并使用此代码设置行的大小:
Set the ScrollBars
property of DataGridView
to None
and use this code to set size of rows:
foreach (DataGridViewRow row in dataGridView1.Rows)
{
row.Height = (dataGridView1.ClientRectangle.Height - dataGridView1.ColumnHeadersHeight) / dataGridView1.Rows.Count;
}
还可以使用此代码来处理调整大小:
Also use this code to handle resizing:
private void dataGridView1_SizeChanged(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
row.Height = (dataGridView1.ClientRectangle.Height - dataGridView1.ColumnHeadersHeight) / dataGridView1.Rows.Count;
}
}
这篇关于如何调整datagridview中的行大小,以便它们填充整个控件,并且都具有相同的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!