如何根据行数限制wpf datagridview的高度?

时间:2020-12-03 09:13:41

how do I set the height of the datagridview based on number of visible rows. Let's say I have a datagridview with datasource, having 100 rows. I want the viewable area to show only 10 rows. The other rows can be viewed with scrolling.

如何根据可见行数设置datagridview的高度。假设我有一个带数据源的datagridview,有100行。我希望可视区域只显示10行。可以通过滚动查看其他行。

2 个解决方案

#1


1  

Height is a dependencyproperty; you can bind the height of your grid control to the height of one gridrow * 10

高度是一种依赖属性;您可以将网格控件的高度绑定到一个gridrow * 10的高度

#2


0  

You get the height of 1 of your rows... and then multiply by the number of rows you wish to see.

您获得1行的高度...然后乘以您希望看到的行数。

myGrid.Height = rowHeight * 10

myGrid.Height = rowHeight * 10

(No one seems to know how to determine "rowHeight" correctly. You also have to take into account the thickness of your borders between each row.)

(似乎没有人知道如何正确地确定“rowHeight”。你还必须考虑每行之间边界的厚度。)

#1


1  

Height is a dependencyproperty; you can bind the height of your grid control to the height of one gridrow * 10

高度是一种依赖属性;您可以将网格控件的高度绑定到一个gridrow * 10的高度

#2


0  

You get the height of 1 of your rows... and then multiply by the number of rows you wish to see.

您获得1行的高度...然后乘以您希望看到的行数。

myGrid.Height = rowHeight * 10

myGrid.Height = rowHeight * 10

(No one seems to know how to determine "rowHeight" correctly. You also have to take into account the thickness of your borders between each row.)

(似乎没有人知道如何正确地确定“rowHeight”。你还必须考虑每行之间边界的厚度。)