Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > How to resize Rows and Columns in a DataGridView in order to adjust to the size of the container
 

How to resize Rows and Columns in a DataGridView in order to adjust to the size of the container

Hi everyone,

I would like to know how I can resize the Rows and the Columns in a DataGridView in order to adjust to the size of the container of this. So if I have 5 columns and 5 rows, I would like to occupy all the spaces available. Thank you very much for any help.


CardSpace
AsToni  Monday, September 28, 2009 10:04 AM

Hi,

 

Base on my understanding, you want to show gridlines in all display area of datagridview.

 

You can change AutoSizeColumnsMode property to fill. The columns will adjust their width to fill datagridview.

If rows count number is fixed, you can set the rows’ height to adjust datagridview display area.

            this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            dataGridView1.Rows.Add(3);

            dataGridView1.AllowUserToAddRows = false;

 

            foreach (DataGridViewRow r in dataGridView1.Rows)

            {

                r.Height = (dataGridView1.DisplayRectangle.Height - dataGridView1.ColumnHeadersHeight-1) / dataGridView1.Rows.Count;

            }

 

If you want to show rowline dynamically, you can draw the rowlines in datagridview paint event.

The following FAQ tells about this.

13.How to make the DataGridView show gridlines in all display areas?

http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/a44622c0-74e1-463b-97b9-27b87513747e#faq13

 

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Sunday, October 04, 2009 5:23 AM

Hi,

 

Base on my understanding, you want to show gridlines in all display area of datagridview.

 

You can change AutoSizeColumnsMode property to fill. The columns will adjust their width to fill datagridview.

If rows count number is fixed, you can set the rows’ height to adjust datagridview display area.

            this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            dataGridView1.Rows.Add(3);

            dataGridView1.AllowUserToAddRows = false;

 

            foreach (DataGridViewRow r in dataGridView1.Rows)

            {

                r.Height = (dataGridView1.DisplayRectangle.Height - dataGridView1.ColumnHeadersHeight-1) / dataGridView1.Rows.Count;

            }

 

If you want to show rowline dynamically, you can draw the rowlines in datagridview paint event.

The following FAQ tells about this.

13.How to make the DataGridView show gridlines in all display areas?

http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/a44622c0-74e1-463b-97b9-27b87513747e#faq13

 

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Sunday, October 04, 2009 5:23 AM

You can use google to search for other answers

Custom Search

More Threads

• VB2005 / 2008 - BindingNavigatorDeleteButton help needed
• TableAdapters, the worst "feature" of 2.0
• Underlying deletion not updating the display of the selected row in the DataGridView
• How Do I pass a parameter in a text box to a sql stored procedure?
• Use DataGrid to display simple Excel Table?
• Performance very slow when populating data in Grid from remote database
• DataGridViewCheckboxCell won't show the correct value until another cell is selected
• Hide new row column until save
• Tab not working on the textbox control causing null values in the currencymanager
• how to reading inbox messages in C#