1

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.

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?

4

3 回答 3

6

尝试继承 DataGridView 并处理 VerticalScrollBar 的 VisibleChanged 事件。您应该能够在其中将 Visible 属性设置为 True,从而覆盖默认行为。

像这样的东西,我想...

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

        void VerticalScrollBar_VisibleChanged(object sender, EventArgs e)
        {
            VerticalScrollBar.Visible = true;
        }
     }
于 2009-01-23T13:10:56.853 回答
1

就我而言,(重新)对网格进行排序很有帮助。像这样尝试:

 if (gridName.SortedColumn == null)
   gridName.Sort(gridNameColumns[columnName],ListSortDirection.Ascending);
 else
 {
    ListSortDirection dir;
    if (gridName.SortOrder == SortOrder.Descending) 
       dir = ListSortDirection.Descending;
    else dir = ListSortDirection.Ascending;

    gridName.Sort(gridName.SortedColumn, dir);
 }
于 2011-12-21T14:19:25.297 回答
0

一种可能性是触发滚动条消失的事件,以便您可以阻止该事件并停止它。

于 2020-08-24T13:31:32.870 回答