水平滚动条在 DataGridView 上不可见

发布于 2024-10-20 16:06:58 字数 253 浏览 9 评论 0原文

我在 Window 窗体上有一个 DataGridView,其中填充了 30 列和数千行。 ScrollBars 属性设置为 Both,但水平滚动条仍然不可见。即使我无法使用键盘上的箭头键滚动。

我也尝试将 ScrollBars 属性设置为 Horizo​​ntal ,但这没有任何区别。

请问有什么建议吗?

谢谢

I have a DataGridView on Window form which is populated with 30 columns and thousands of rows.
ScrollBars property is set to Both, but still horizontal scroll bar is not visible. even I am unable to scroll with arrow key from keyboard.

I tried it by setting ScrollBars property to Horizontal as well, but that does not make any difference.

Any suggestions please?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(21

世俗缘 2024-10-27 16:06:58

好吧,伙计们,事情已经解决了。

我正在回答我自己的问题;它可能会对将来的某人有所帮助。

其中一列的 Frozen 属性设置为 True。所有列都应为 false
现在 ScrollBar 对我来说工作得非常好。

干杯

在此处输入图像描述

Well Guys, its sorted out.

I am answering my own question; it may help someone in future.

one of the columns has Frozen property set as True. which should be false for all columns.
Now ScrollBar is working absolutely fine for me.

Cheers

enter image description here

迷迭香的记忆 2024-10-27 16:06:58

我知道这个问题已经解决了,但我遇到了可能发生这种情况的另一个原因,所以我想将其添加为答案,以防其他人遇到同样的问题。

如果您的表单具有停靠以填充表单的 DataGridView,并且表单还具有状态栏,则根据它们的创建顺序,状态栏可以隐藏 DataGridView 的滚动条。要解决此问题,请右键单击 DataGridView,然后选择“置于前面”。

I know this has already been resolved, but I've come across another reason why this could happen, so thought I'd add it as an answer in case someone else has the same problem.

If your form has a DataGridView that is docked to fill the form, and the form also has a status bar, then depending on the order they're created, the status bar can hide the DataGridView's scrollbar. To fix this, right click on the DataGridView, and select "Bring to Front".

不爱素颜 2024-10-27 16:06:58

当我遇到这个恼人的问题时,这是由于 DGV 的 AutoSizeColumnsMode 属性设置为 Fill

我通过将该属性更改为 AllCells 来修复它code>,但任何其他值都可以。即使 DGV 已对接且我有多个对接面板且第一列处于“冻结”状态,它也能正常工作。

When I encountered this annoying problem, it was due to the AutoSizeColumnsMode property of the DGV that was set to Fill

I fixed it by changing that property to AllCells, but any other value will work. It works even if the DGV is docked and I have multiple docked panels, and the first column is Frozen.

并安 2024-10-27 16:06:58

DGV 的对接.Fill 有点问题。
当您有多个停靠面板、工具栏等时,就会发生这种情况。
当您在运行时创建列时更常见。

该控件认为它比其容器宽,并且水平滚动条不会生成。

冻结、自动调整大小、放在前面以及提到的其他补救措施并不总是有效。
最可靠的解决方法是 Dock.Left 并在运行时设置 DGV 的宽度。
这样 DGV 就不会对其宽度感到困惑。

The docking.Fill of the DGV is a little buggy.
It happens when you have multiple docked panels, toolbars, etc.
More common when you're creating your columns at runtime.

The control thinks it is wider than its container and the Horizontal scrollbar does not spawn.

Frozen, autosize, brint to front and the other remedies mentioned don't always work.
The most reliable workaround is to Dock.Left and set the DGV's width at run time.
This way the DGV doesn't get confused about how wide it is.

尘曦 2024-10-27 16:06:58

我有类似的问题。我所做的是,检查每个数据网格列并将冻结设置为“false”。希望有帮助。

i had the similar problem. What I did was, check each of your Datagrid columns and set the Frozen to "false". Hope that helps.

本王不退位尔等都是臣 2024-10-27 16:06:58

我遇到了这个恼人的问题。我已经在表单上创建了 DataGridView,并在 .CS 文件中设置所有数据绑定和属性设置。

我只是在文件(.cs)后面的代码中注释了该行,即

gvTblContent.AutoSize = true;

您不需要设置 AutoSize 属性,默认情况下将提供水平和垂直滚动条,否则您可以使用:

gvTblContent.ScrollBars = ScrollBars.Both;

I was having this irritating problem. I had already created the DataGridView on my Form and am setting all the databinding and properties setting in the .CS file.

I just commented the line in my code behind file (.cs) i.e.

gvTblContent.AutoSize = true;

You need not to set the AutoSize property, horizontal and vertical scrollbars will be provided by default otherwise you can use :

gvTblContent.ScrollBars = ScrollBars.Both;
七七 2024-10-27 16:06:58

在我以编程方式添加一些行后,我遇到了类似的问题,不是由于 frozen 属性,而是最有可能是 DataGridView 错误。在阅读了另一个问题的这个答案后,我使用以下方法解决了:

dgv.PerformLayout()

添加这些行之后,就在 dgv 之前即将展示。

I had a similar problem, not due to the frozen property, but most likely to DataGridView bugs, after I added some rows programmatically. After reading this answer to another question I solved using:

dgv.PerformLayout()

after adding those rows, just before dgv was about to be shown.

ぶ宁プ宁ぶ 2024-10-27 16:06:58

就我而言,我只是使用 Anchor Top、Bottom、Left、Right 而不是 DOCK Fill。

尝试一下。

In my case i just used ANCHOR Top, Bottom, Left, Right instead of DOCK Fill.

Try it.

柏林苍穹下 2024-10-27 16:06:58

所有冻结的列都应适合表格。
否则水平滚动条不会显示。
如果没有水平滚动条,则使表单变宽,直到看到最后一个冻结字段,然后水平滚动条就会神奇地出现。

All your frozen columns should fit within the form.
Otherwise horizontal Scrollbar does not show up.
If there is no horizontal Scrollbar then make your form wider until you see your last frozen field and then Horizontal Scrollbar will magically appear.

み零 2024-10-27 16:06:58

我遇到了类似的问题,但在 SplitContainer 内。以上都不起作用,但使用所有四个锚点而不是 DataGridView 的 Dock.Fill。

I had a similar issue but inside SplitContainer. None of the above worked, but use all four anchors instead of Dock.Fill of DataGridView.

娇妻 2024-10-27 16:06:58

就我而言,数据网格视图位于选项卡控件内。我发现如果单击任何标题对列进行排序,就会显示滚动条。

经过一系列的尝试和错误之后,我让它工作了..

    private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
    {
        //Ran into a strange issue where the Scroll bars would not work on any of the data grids.
        //After a bunch of trial and error, I discovered that once you clicked on a tab and sorted on 
        //a column, it would show up. So this is programically doing it.

        TabPage myTabPage = ((System.Windows.Forms.TabControl)sender).SelectedTab;
        DataGridView myDG = myTabPage.Controls[0] as DataGridView;
        if (myDG != null && myDG.Rows.Count > 0)
        {
            //myDG.Sort(myDG.Columns[0], ListSortDirection.Ascending);  //Basically this should not change the sort order.
            myDG.PerformLayout();  //This seems to work as well, but only in this event, but at least it doesn't change the sort.
        }
    }

In my case, the datagridviews were inside a Tab Control. I found that if I clicked on any of the headers to sort the column, the Scroll bar(s) would show up.

After doing a bunch of trial and error, I got this to work..

    private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
    {
        //Ran into a strange issue where the Scroll bars would not work on any of the data grids.
        //After a bunch of trial and error, I discovered that once you clicked on a tab and sorted on 
        //a column, it would show up. So this is programically doing it.

        TabPage myTabPage = ((System.Windows.Forms.TabControl)sender).SelectedTab;
        DataGridView myDG = myTabPage.Controls[0] as DataGridView;
        if (myDG != null && myDG.Rows.Count > 0)
        {
            //myDG.Sort(myDG.Columns[0], ListSortDirection.Ascending);  //Basically this should not change the sort order.
            myDG.PerformLayout();  //This seems to work as well, but only in this event, but at least it doesn't change the sort.
        }
    }
梦言归人 2024-10-27 16:06:58

我也遇到这个问题。就我而言,这是一个愚蠢的情况。

请检查DataGridView的位置/大小是否不规范。

I also meet this problem. It's a stupid situation in my case.

Please check the position/size of DataGridView whether out of the form.

長街聽風 2024-10-27 16:06:58

我遇到了同样的问题,发现我的 dataGridView 比它所在的表单稍大。我调整了大小以适合表单,它成功了!
希望这有帮助!

I had the same problem and found that my dataGridView was slightly larger than the form that it was in. I adjusted the size to fit in the Form and it worked!
Hope this helps!

霞映澄塘 2024-10-27 16:06:58

我这边的多个显示/隐藏列导致了同样的问题。必须添加
dataGridView1.ScrollBars = ScrollBars.Both;在我处理完 datagridview 中的所有列和行之后,

上面的内容都没有帮助
1. 无冷冻柱
2.表单加载有dataGridView1.ScrollBars = ScrollBars.Both;
3.没有状态栏

Multiple show/hide columns on my side was causing the same issue. Had to add
dataGridView1.ScrollBars = ScrollBars.Both; after I process all the columns and rows in the datagridview

Nothing of the above helped before that
1. No Frozen Columns
2. Form load has dataGridView1.ScrollBars = ScrollBars.Both;
3. No Status bar

魂牵梦绕锁你心扉 2024-10-27 16:06:58

我在 VS2015 的 winform 中也遇到了这个问题。

winform 的表格布局分为 4 行、1 列。在行中,我放置了用于放置其他控件的面板,除了最后一行中的 DataGrid 行。 DataGrid 设置为 Dock 来填充。该表单底部还有一个状态栏,以供将来使用。

我发现状态栏挡住了滚动条,如前所述。

我在表布局中添加了另一行,但这在运行时和设计时都会在表单底部显示一个大的空白区域。调整表单大小也没有解决。我尝试设置表格布局的行高,但它不起作用。我尝试了 1 像素、5 像素等,没有变化。最后我放弃并删除了状态栏,无论如何也没有使用它。

I too had this problem in VS2015 on a winform.

The winform has a table layout split into 4 rows, 1 column. Into the rows I place panels for placing other controls except the DataGrid row which is in the last row. The DataGrid is set with Dock to fill. The form also has a Status bar at the bottom, for future use.

What I found is that the status bar blocked the scrollbar as mentioned previously.

I added another row to the table layout but that would display a large blank space at the bottom of the form both at run time and design. Resizing the form did not resolve either. I tried setting the row height of the table layout but it did not work. I tried 1 pixel, 5 pixels etc. no change. In the end I gave up and removed the Status bar, wasn't using it for anything anyway.

不忘初心 2024-10-27 16:06:58

我有一个 DataGridView 位于 TableLayoutPanel 的单元格内,并且两个滚动条都没有显示在 DataGridView 上。我认为 DataGridView 的大小也没有得到正确管理,DataGridView 被停靠以填充 TableLayoutPanel 的单元格。我没有任何冻结的列。

我可以通过将 DataGridView 放置在面板中并在面板上设置 AutoScroll=true 来修复它,让面板管理滚动。我停靠面板以填充 TableLayoutPanel 的单元格内部,并停靠 DataGridView 以填充面板内部。

I had a DataGridView sitting inside a cell of a TableLayoutPanel, and neither scroll bar was showing up on the DataGridView. I think the size of the DataGridView also wasn't being managed properly with the DataGridView being docked to fill a cell of the TableLayoutPanel. I didn't have any frozen columns.

I was able to fix it by placing the DataGridView inside a Panel, and setting AutoScroll=true on the Panel, to let the Panel manage the scrolling. I docked the panel to fill inside the cell of the TableLayoutPanel, and docked the DataGridView to fill inside of the Panel.

梦初启 2024-10-27 16:06:58

就我而言,直到我意识到上面的冻结列状态和只读状态时,滚动条才出现。我已经为只读列以及 dataGridView 中的一个可编辑列完成了冻结列。当我删除可编辑列的 frozen=false 时,会出现水平条。

In my case Scroll bar didn't appear until when I realized the above frozen column state and read-only. I have done frozen columns for read-only column as well the one editable column in my dataGridView. When I remove frozen=false for editable column, the horizontal bar appear.

极致的悲 2024-10-27 16:06:58

我将一些第一列冻结为 true 它(H_bar)仍然有效。但我将 freeze = true 设置为不可见列(column.visible = false),它消失了。

I set some first columns frozen to true it(H_bar) still works. But I set frozen = true to a invisible column (column.visible=false), it gone.

抚笙 2024-10-27 16:06:58

我在 tableLayoutPanel 内的 DataGridView 遇到了同样的问题。

以上都没有帮助我。

原来是DataGridView所在的tableLayoutPanel中的列设置为AutoSize

解决方案是将 tableLayoutPanel 列设置为实际值或百分比。

I had the same problem with DataGridView inside a tableLayoutPanel.

None of the above helped me.

It turns out that the column in the tableLayoutPanel in which the DataGridView is is set to AutoSize.

The solution is to set the tableLayoutPanel columns to actual value or percent.

橘虞初梦 2024-10-27 16:06:58

您还可以检查一件事。 GridView 控件的“Enabled”属性应设置为“true”。
DataGridView 属性:

There one more thing you could check on. The "Enabled" property of the GridView control should be set at "true".
DataGridView Properties:

比忠 2024-10-27 16:06:58

解决了我的问题,但不是以上任何一个。

在我的情况下,我是在运行时创建整个表单。每个 DataGridView 都是 TableLayoutPanel 内的 Dock.Fill。如果只有一个 TableLayoutPanel,则不必指定行或列,并且应该为 100%。然而这样做会破坏 DataGridView。只需添加行 100% 定义即可解决我的问题。

Fixed my problem, but it was none of the above.

In my situation, I was creating my entire form at run-time. Each DataGridView was Dock.Fill inside a TableLayoutPanel. You don't have to specify row or columns for a TableLayoutPanel if there is only going to be one, and it should be 100%. Doing this however breaks DataGridView. Fixed my problem by simply adding the row 100% definition.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文