DataGridView中的ScrollBar [英] ScrollBar in DataGridView

查看:299
本文介绍了DataGridView中的ScrollBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VS2008中有一个包含DataGridView的winform。 datagrid包含一列有多列的列表。这些是固定的宽度,我已经设置了一个,以占用任何空间留下并填充视图的宽度。 winform可以在所有方向重新调整大小。

I have a winform in vs2008 that contains a DataGridView. The datagrid contains a list with several columns. These are fixed width, exept one that I have set up to take whatever space is left and fill the width of the view. The winform is resizeable in all directions.

我想要解决的问题是当我增加窗口的垂直尺寸时,滚动条消失,列对齐有权填补额外的空间。我想要发生的是垂直scrollBar从不消失。在DataGridView的属性中将ScrollBars设置为垂直不会这样做。

The issue I am trying to solve is that when I increase the vertical size of the window the scrollbar disappears and the columns snap to the right to fill the extra space. What I would like to happen is that the vertical scrollBar never disappears. Setting ScrollBars to vertical in the properties of the DataGridView does not do this.

这是否可以实现?而且,如果是这样,我如何使垂直滚动条总是可见?

Is this at all possible to achieve? And, if so, how do I get the vertical scrollbar to always be visible?

推荐答案

尝试将DataGridView子类化并处理VerticalScrollBar VisibleChanged事件。您应该能够将Visible属性设置为True,覆盖默认行为。

Try subclassing the DataGridView and handling the VerticalScrollBar's VisibleChanged event. You should be able to set the Visible property to True in there, overriding the default behaviour.

这样的事情,我想...

Something like this, I think...

public class SubclassedDataGridView : DataGridView
    {
        public SubclassedDataGridView (): base()
        {
            VerticalScrollBar.VisibleChanged += new EventHandler(VerticalScrollBar_VisibleChanged);
        }

        void VerticalScrollBar_VisibleChanged(object sender, EventArgs e)
        {
            VerticalScrollBar.Visible = true;
        }
     }

这篇关于DataGridView中的ScrollBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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