[英]How do I set the row height of a DataGrid in WinForms?
How do I set the row height in DataGrid? 如何在DataGrid中设置行高? I don't see any property anywhere to achieve that. 我看不到任何实现此目的的属性。 I am using .NET 3.5 and it's a WinForms application written in C#. 我正在使用.NET 3.5,它是用C#编写的WinForms应用程序。
EDITED 已编辑
Here is the piece of code that assigns the datasouce, you can see that I set the prefered height before that 这是分配数据源的代码,您可以看到我在此之前设置了首选高度
dgMyGrid.PreferredRowHeight = 64;
dgMyGrid.DataSource = samples;
If I remember well there is a property named PreferredRowHeight. 如果我还记得的话,有一个名为PreferredRowHeight的属性。 Should be set before the databinding. 应该在数据绑定之前设置。
Steve's answer works: 史蒂夫的答案有效:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
dataGrid1.PreferredRowHeight = 64;
myTableAdapter.Fill(myDataSet.myTable);
}
}
Will produce a grid with rows at a height of 64. However, this doesn't work: 将产生一个高度为64行的网格。但是,这不起作用:
private void Form1_Load(object sender, EventArgs e)
{
myTableAdapter.Fill(myDataSet.myTable);
dataGrid1.PreferredRowHeight = 64; // has no effect because the grid is already drawn
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.