Scorpion
Scorpion

Reputation: 4575

Horizontal Scrollbar is not visible on DataGridView

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

Upvotes: 24

Views: 79411

Answers (21)

da_jokker
da_jokker

Reputation: 1023

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.
        }
    }

Upvotes: 1

Max
Max

Reputation: 771

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

Upvotes: 1

Dan
Dan

Reputation: 61

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.

Upvotes: 0

user12616324
user12616324

Reputation: 1

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

Upvotes: 0

Fabius Wiesner
Fabius Wiesner

Reputation: 926

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.

Upvotes: 2

Boris Vaiser
Boris Vaiser

Reputation: 11

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.

Upvotes: 1

Emil Gospodinov
Emil Gospodinov

Reputation: 1

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.

Upvotes: 0

Huỳnh Hữu Ân
Huỳnh Hữu Ân

Reputation: 97

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.

Upvotes: 0

Kishor Oswal
Kishor Oswal

Reputation: 1

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.

Upvotes: 0

chinookf
chinookf

Reputation: 310

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.

Upvotes: 0

iltaf
iltaf

Reputation: 49

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;

Upvotes: 4

Larry
Larry

Reputation: 187

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.

Upvotes: 0

Nikolay Popov
Nikolay Popov

Reputation: 1

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

Upvotes: 0

Raymond Dumalaog
Raymond Dumalaog

Reputation: 353

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

Upvotes: 5

NoWar
NoWar

Reputation: 37633

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

Try it.

Upvotes: 1

Robbie
Robbie

Reputation: 1

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!

Upvotes: 0

Fabio Michelini
Fabio Michelini

Reputation: 1117

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.

Upvotes: 10

Mystic Lin
Mystic Lin

Reputation: 375

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.

Upvotes: 0

Joe
Joe

Reputation: 61

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.

Upvotes: 6

Dan
Dan

Reputation: 5972

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".

Upvotes: 23

Scorpion
Scorpion

Reputation: 4575

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

Upvotes: 49

Related Questions