Sizing the column header's

OmkarHcl 206 Reputation points
2023-10-08T11:49:48.1333333+00:00

Hi ,
User's image

I have a datagridview with 5 columns . during run time i saw that there is some space left as shown the figure . Can we adjust it at so that it must not show if in the future the number of columns increase or decrease .

Developer technologies | Windows Forms
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

1 answer

Sort by: Most helpful
  1. KOZ6.0 6,735 Reputation points
    2023-10-08T12:38:56.7466667+00:00
    dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
    

    or Set the AutoSizeMode of the last column to Fill

    var column = dataGridView1.Columns.GetLastColumn(DataGridViewElementStates.Visible,
                                        DataGridViewElementStates.None);
    column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
    

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.