How to add scrollbar in Datagridview VB?

Asked

Viewed 333 times

3

I need to add a scroll bar for the amount of lines in a DataGridView, because I don’t want to work with pagination, then the question arises, how to do?

  • You’re making a Winform?

  • Yes, I put a dataGridView in a Form, fill this, but the data of the database exceeds the size of it, thus needing a Scroll.

1 answer

0

The scroll of datagridview appears when it is with records that no longer fit on the screen.

Create a new form and add a new one datagridview

Put this code in the load.

string[] row0 = { "11/22/1968", "29", "Revolution 9",
            "Beatles", "The Beatles [White Album]" };
            dataGridView1.ColumnCount = 5;

            dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Navy;
            dataGridView1.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
            dataGridView1.ColumnHeadersDefaultCellStyle.Font =
                new Font(dataGridView1.Font, FontStyle.Bold);

            dataGridView1.Location = new Point(8, 8);
            dataGridView1.Size = new Size(500, 250);
            dataGridView1.AutoSizeRowsMode =
                DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;
            dataGridView1.ColumnHeadersBorderStyle =
                DataGridViewHeaderBorderStyle.Single;
            dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.Single;
            dataGridView1.GridColor = Color.Black;
            dataGridView1.RowHeadersVisible = false;

            dataGridView1.Columns[0].Name = "Release Date";
            dataGridView1.Columns[1].Name = "Track";
            dataGridView1.Columns[2].Name = "Title";
            dataGridView1.Columns[3].Name = "Artist";
            dataGridView1.Columns[4].Name = "Album";
            dataGridView1.Columns[4].DefaultCellStyle.Font =
                new Font(dataGridView1.DefaultCellStyle.Font, FontStyle.Italic);

            dataGridView1.SelectionMode =
                DataGridViewSelectionMode.FullRowSelect;
            dataGridView1.MultiSelect = false;
            dataGridView1.Dock = DockStyle.Fill;

            //songsDataGridView.CellFormatting += new
            //    DataGridViewCellFormattingEventHandler(
            //    songsDataGridView_CellFormatting);
            dataGridView1.Rows.Add(row0);
            dataGridView1.Rows.Add(row0);
            dataGridView1.Rows.Add(row0);
            dataGridView1.Rows.Add(row0);
            dataGridView1.Rows.Add(row0);
            dataGridView1.Rows.Add(row0);
            dataGridView1.Rows.Add(row0);
            dataGridView1.Rows.Add(row0);

            dataGridView1.Rows.Add(row0);
            dataGridView1.Rows.Add(row0);
            dataGridView1.Rows.Add(row0);
            dataGridView1.Rows.Add(row0);
            dataGridView1.Rows.Add(row0);
            dataGridView1.Rows.Add(row0);



            dataGridView1.Columns[0].DisplayIndex = 3;

Rotate and reduce the size of form. Stay like this:

inserir a descrição da imagem aqui

Now increases the size of form. Stay like this:

inserir a descrição da imagem aqui

This is the standard behavior of the component.

Try to convert the code to Vb, it will work the same way.

  • Could you tell me, on what line of code, specifically if you define the scroll, why I couldn’t see.

  • None of them, by default he already has the scroll, what must be happening is that you must have configured something that disabled. Give a read here that he talks about some things that can take the scroll. I will not be on the computer for now. If you don’t help, tell me here that I’ll test them. http://stackoverflow.com/a/10833212/3517631

Browser other questions tagged

You are not signed in. Login or sign up in order to post.