How to resize the gridview in

QuestionsCategory: WinFormHow to resize the gridview in
AnynoumusAnynoumus asked 1 year ago

On windows form, How to resize the gridview in

1 Answers
Best Answer
Mahesh DeshmaneMahesh Deshmane answered 1 year ago

If you want to resize data grid view control when form resizes, you can try below solutions:
solution 1:  Set the property of your DataGridView to auto resize grid view based on parent:

Anchor: Top,Left
AutoSizeColumn: Fill
Dock: Fill

solution 2:
Use dock property of data grid view to automatically change it’s size based on parent.
solution 3:
create an event handler that resizes the grid appropriately, example:

private void frm_sizeChanged(object sender, EventArgs e)
     dataGrid.Size = new Size(100, 200);

We can use explicit the size of data grid view
this is not the question but still If you want to resize column   of data grid view
solution 1:
Setting data grid AutoResizeColumns property to resize column of data grid view


dataGrid1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;

by setting AutoSizeColumnsMode and AutoSizeColumnsMode

dataGrid1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGrid1rid.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;

solution 2:
individual Columns using AutoSizeMode property to resize column of data grid view

dataGrid1.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
dataGrid1.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
dataGrid1.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

solution 3:
We can explicitly provide column size to resize data grid column view:

dataGridView1.Columns[1].Width = 80;
dataGridView1.Columns[2].Width = 80;