以编程方式调整DataGridView的大小以删除滚动条. [英] Programmatically resize DataGridView to remove scroll bars.

查看:129
本文介绍了以编程方式调整DataGridView的大小以删除滚动条.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataGridView,它具有用户可定义的数字数据列数(从〜6-60到任何地方).在较高端,网格中的数据量超过了可以立即在屏幕上显示的数据量.我有一个数据图.我想使两者保持同步,以便图形上的特定时间T与网格中​​的相同时间垂直对齐.

为此,我想使DataGridView足够宽,以避免出现滚动条,使图形具有相同的宽度,然后将滚动内容卸载到容器控件上.但是,我找不到直接获取宽度的方法,需要将DataGridView设置为该宽度才能从中删除滚动条.

I have a DataGridView with a user definable number of columns (anywhere from ~6-60) of numerical data. At the higher end that amount of data in the grid exceeds that which can be displayed on screen at once. I have a graph that goes with the data. I would like to keep the two in sync, so that a specific time T on the graph is in line vertically with the same time in the grid.

To do this I''d like to make the DataGridView just wide enough to avoid a scroll bar, have the graph be equally wide, and then offload the scrolling onto a container control. However, I can''t find a way to directly get the width I''d need to set the DataGridView to in order to remove the scroll bar from it.

推荐答案

好像,您可以固定图表和DataGridView的大小,而只需使用AutoSizeColumnMode即可使视图中的列适合滚动条.
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.autosizecolumnsmode.aspx [ ^ ]
Seems like, you can have your chart and DataGridView fixed sized, and just use the AutoSizeColumnMode to fit the columns in view without scrollbar.
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.autosizecolumnsmode.aspx[^]


Wizardzz处在正确的轨道上;我是从另一个网站获得的:

Wizardzz was on the right track; I got this from another site:

/// <summary>
/// Return the minimum width in pixels a DataGridView can be before the control''s vertical scrollbar would be displayed.
/// </summary>
private int GetDataGridViewMinWidth(DataGridView dataGridView) {
    // Add two pixels for the border for BorderStyles other than None.
    var controlBorderWidth = (dataGridView.BorderStyle == BorderStyle.None) ? 0 : 2;

    // Return the width of all columns plus the row header, and adjusted for the DataGridView''s BorderStyle.
    return dataGridView.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) + dataGridView.RowHeadersWidth + controlBorderWidth;
}


这篇关于以编程方式调整DataGridView的大小以删除滚动条.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆