I need to add a scrollbar for the number of lines in a DataGridView
, since I do not want to work with pagination, here comes the question, how do I do it?
I need to add a scrollbar for the number of lines in a DataGridView
, since I do not want to work with pagination, here comes the question, how do I do it?
The datagridview
scroll appears when it has records that no longer fit on the screen.
Create a new form and add a new 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;
Run and reduce the size of form
. It looks like this:
Nowincreasethesizeofform
.Itlookslikethis:
This is the default behavior of the component.
Try to convert the code to vb, it will work the same way.