Why does my DataGridView resist displaying the bottom data and how do I fix it?

clweeks

I have a form with a DataGridView. I format it like this:

dgvECN.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None
dgvECN.Columns(0).Width = 50
...
dgvECN.Columns(15).Width = 100
dgvECN.DefaultCellStyle.WrapMode = DataGridViewTriState.True

The grid always has more data than will appear on one screen, so I rely on scrollbars -- primarily the vertical. If I grab the scrollbar with the mouse and drag it as far down as it will go, it stops maybe ~97% of the way down the bar, as if I'd reached the bottom and there are more rows of data that I haven' not yet scrolled to. I can release the scrollbar and grab it again and drag it down and it will go down further, but not all the way. On the fourth try (with the current data), it reaches the bottom.

I can hold down the down-arrow at the bottom of the scroll-bar and that works. I can cursor/arrow down or page-down all the way to the bottom. When I do any of those things, the scroll-handle jitters down and then up a little like it's recalculating or something.

I have tried having the form load with the bottom of the data showing by using:

dgvECN.FirstDisplayedScrollingRowIndex = dgvECN.RowCount - 1

But that scrolls the view to around the region of data where the grid seems to initially think the bottom is, rather than the actual bottom.

I think this is my first time working with wrapping text inside the grid's cells, so I suspect that as a cause.

But I've been reading and reading and while I've found plenty of exotic bugs and errors that sound related at first, they all end up not being my issue and I haven't found anything that fixes it.

Feel free to ask in the comment for specific info about my project, I'm not sure what you might need to help diagnose this. And thanks for your time!

ETA: .NET 4.0 and VS Express 2013, in case it matters.

ETA2: I've attempted to set the on-load display so that it's showing the bottom of the data rather than that top. I'm doing this with:

dgvECN.CurrentCell = dgvECN.Item(0, dgvECN.Rows.Count - 1)

But that doesn't actually take it to the bottom of the data. I imagine this is a manifestation of the same error.

ETA3: This is what it looks like when it loads with the current cell set to the bottom row: bugged DataGridView

ETA4: the DataGridView Designer code:

    '
    'dgvECN
    '
    Me.dgvECN.AllowUserToAddRows = False
    Me.dgvECN.AllowUserToDeleteRows = False
    Me.dgvECN.AllowUserToOrderColumns = True
    Me.dgvECN.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
        Or System.Windows.Forms.AnchorStyles.Left) _
        Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
    Me.dgvECN.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill
    Me.dgvECN.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
    Me.dgvECN.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
    Me.dgvECN.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Me.Check})
    Me.dgvECN.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically
    Me.dgvECN.Location = New System.Drawing.Point(3, 3)
    Me.dgvECN.Name = "dgvECN"
    Me.dgvECN.Size = New System.Drawing.Size(1102, 670)
    Me.dgvECN.TabIndex = 5
Moop

Here is a test program for this problem (written in C#, but should be applicable to VB). It assumes you have one DataGridView named dataGridView1.

The AutoSizeRowsMode property should be set to DataGridViewAutoSizeRowsMode.AllCells to avoid the problem you are facing.

        DataTable data = new DataTable("Example");
        data.Columns.Add("1");
        data.Columns.Add("2");
        data.Columns.Add("3");
        data.Columns.Add("4");

        for (int i = 0; i < 2000; i++)
        {
            data.Rows.Add(new []
                {
                    "1",
                    "2",
                    "LONG STRING THAT SHOULD WRAP TO MULTIPLE LINES",
                    "4"
                });
        }
        data.Rows.Add(new[]
                {
                    "1",
                    "2",
                    "LONG STRING THAT SHOULD WRAP TO MULTIPLE LINES",
                    "Last Row!!!"
                });

        dataGridView1.AllowUserToAddRows = false;
        dataGridView1.AllowUserToDeleteRows = false;
        dataGridView1.AllowUserToOrderColumns = true;
        dataGridView1.AutoSizeColumnsMode =DataGridViewAutoSizeColumnsMode.Fill; 
        dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders; // Appears that this line should be `AllCells` to avoid the problem you are facing
        dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
        dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
        dataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically;
        dataGridView1.DataSource = data;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why is the gutter padding not displaying in one of my Bootstrap webpage content block and how do I fix it?

How do I fix IF/ELSE program not displaying or sorting data?

Why does my 'for' loop break due to a boolean set-membership check, and how do I fix it?

Why does mongodb change my date formats to long number and how do I fix it?

Why does Bootstrap destroys my normal css layout and how do I fix it?

Why does my tool output overwrite itself and how do I fix it?

Why does decreasing the size of the renderer offset my click events - How do I fix this

My buttons do not respond unless I enlarge the bottom splitter bar in Kivy; how do I fix that?

The box of GUILayout.TextField disappears when I try to center my text, why does it do that and how do I fix it?

How do I Fix this Bizarre DataGridview Behavior

Why does my Makefile not compile and how can I fix it?

How do I configure my Linksys routers to resist the WPS brute-force vulnerability?

Why is my actionbar not showing and how do I fix it?

Why is my while going in a infinity loop? How do I fix it?

Why are months in my date slicer repeating? How do I fix it?

How do I fix my Javascript function that does not work?

HTML Header bottom border does not wrap arround ToC, but the text does. How do I fix this?

Why is my icon not displaying on my webpage and how do I do a hover effect?

Why does Bazel under-link and how do I fix it?

Why does Vim delay on this remapped key? And how do I fix it?

I have a server application that gets data exactly half the time. Why/how does this happen and how do I fix it?

How do I fix overflow with TextFormField keyboard and the buttons on the bottom of my page?

My code keeps displaying an error when I run it on Python Tutor saying: "Too many to unpack". How do I fix this error?

Why does my code deadlock and how to fix it

Why does adding margin to my table move donw my sidebar and how can I fix this?

responsive screen, when I minimize from full screen my right column goes to the bottom. How do I fix this?

C programming: why are my decimals not displaying & how do I define black spaces

How do I fix the output from always displaying 0 in the console?

How do I fix TortoiseSVN displaying random icon overlays?

TOP Ranking

HotTag

Archive