English 中文(简体)
为什么数据匮乏 观点不适于浏览?
原标题:Why is DataGridView not sizing to fit rows?

我正试图为我的习俗 com子制造一个没有边界的 drop。 下降表包括用户可以从中选择项目的电网。 大部分工作是行之有效的。 但是,我注意到,电网底有没有数据的空间。 我把允许User ToAddRows伪造。 额外空间甚至包括任何单向控制空间的电池。 为了确保额外空间处于电网(而不是电网),我把电网背景Color设定为黄色,并且以表格显示,因此我知道网格外空间。

注:我正在按方案方式增加电网。 我不敢肯定这一点。 而且,我根据电网规模重新调整表格。 表格的宽度被排在电网上。 如果电网包含10多个电网,则我确定显示只有10个电网的形式高度,垂直滚动条使用户能够进行滚动。 如果电网包含的电网少于10个,那么我就确定适合这些电网的形式,而不需要垂直的滚动条。 这对电网面积有什么影响?

我现在以显露活动的形式做如下工作,以根据电网内容重新确定表格。 请注意,这可能会有打字,因为我从印刷版中重新分类。 注:MaxRows ToShow=10。

int rowsHeight = _grid.Rows.GetRowsHeight(DataGridViewElementStates.Visible);
int rowCount = _grid.Rows.GetRowCount(DataGridViewElementStates.Visible);
int rowHeight = _grid.RowTemplate.Height;
int rowsToShow = Math.Min(MaxRowsToShow, rowCount);
Height = rowsToShow * rowHeight + _grid.ColumnHeadersHeight;

UPDATE: I made some progress. I found out that setting the DataGridView s ScrollBars property to ScrollBars.Vertical was causing the extra space at the end of the grid. If I set ScrollBars to ScrollBars.None when I have less that 10 items, I do not see the extra space. But, I still need the verticall scroll bars when I have more than 10 items, so I m still seeing the extra space in that case. But, at least I figured out the source of the problem. Does anyone know why the ScrollBars property is causing this weird behavior.

问题回答

您:

VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"

?

您基本上是否拥有与电网相同的用户控制或形式?

如果是的话,就确定形式的规模。 如果使用这种控制,那么这种控制就会规模大,但它却需要大量布局。 然后将集装箱控制在形式上,并将集装箱(例如小组)装到Dock-> Fill。 然后将电网放在该集装箱上,并将它放到Dock-> Fill。 然后停止试图确定电网的高度和 st子。 它将拥有其集装箱的任何房间。

Winforms is meant to have controls inherit their parents widths and heights and be sized to fit in them; by resetting the form to match the grid, it s sort of backwards. The user (or program) should resize the form, and the grid will size along with it.

如果电网板拿到整个形式,那么你就只能把集装箱分开,并且可以把电网Anchor排在顶/左/右(顶填充)上,而不是把Dock财产放在一起。





相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.

热门标签