ContentPenalty
ContentPenalty

Reputation: 477

Scrolling on Panel instead DataGridView

I would like to insert my datagridview into a panel with scrollbars. What I have done is setting AutoScroll on the panel to true, make the datagridview fill the panel and disable the scrollbars on it but the scrollbars are not showing on the panel when datagridview have many elements. Any ideas?

Upvotes: 2

Views: 1557

Answers (1)

TaW
TaW

Reputation: 54433

Don't make the DataGridView Dock.Fill the Panel, make it as large as you need to display all Rowsand all Columns!

You need to determine the full Size needed to display all Columns and all Rows without Scrollbars:

int width = 0;
int height = 0;
foreach (DataGridViewColumn col in dataGridView1.Columns) width += col.Width;
foreach (DataGridViewRow row in dataGridView1.Rows) height += row.Height;
dataGridView1.Size = new Size(width,height);

Upvotes: 1

Related Questions