Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 259519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:16:15+00:00 2026-05-11T22:16:15+00:00

I am populating a DataGridView control on a Windows Form (C# 2.0 not WPF).

  • 0

I am populating a DataGridView control on a Windows Form (C# 2.0 not WPF).

My goal is to display a grid that neatly fills all available width with cells – i.e. no unused (dark grey) areas down the right and sizes each column appropriately according to the data it contains, but also allows the user to resize any of the columns to their liking.

I am attempting to achieve this by setting the AutoSizeMode of each column to be DataGridViewAutoSizeColumnMode.AllCells except for one of the columns which I set to DataGridViewAutoSizeColumnMode.Fill in order to ensure the entire area of the grid is neatly filled with data. (I don’t mind that when the user attempt to resize this column it springs back to a size that ensures the horizontal space is always used.)

However, as I mentioned, once loaded I would like to allow the user to resize the columns to suit their own requirements – in setting these AutoSizeMode values for each column it appears the user is then unable to then resize those columns.

I’ve tried not setting the AutoSizeMode of all the columns which does allow resizing BUT doesn’t set the initial size according to the data the cells contain. The same result occurs when changing the grid’s AutoSizeMode back to “Not Set” after loading the data.

Is there a setting I’m missing here which allows automatic setting of default column widths AND user resizing or is there another technique I must use when populating the DataGridView control?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T22:16:15+00:00Added an answer on May 11, 2026 at 10:16 pm

    This trick works for me:

    grd.DataSource = DT;
        
    // Set your desired AutoSize Mode:
    grd.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
    grd.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
    grd.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
        
    // Now that DataGridView has calculated it's Widths; we can now store each column Width values.
    for (int i = 0; i <= grd.Columns.Count - 1; i++)
    {
        // Store Auto Sized Widths:
        int colw = grd.Columns[i].Width;
        
        // Remove AutoSizing:
        grd.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
        
        // Set Width to calculated AutoSize value:
        grd.Columns[i].Width = colw;
    }
    

    In the Code above:
    You set the Columns AutoSize Property to whatever AutoSizeMode you need.
    Then (Column by Column) you store each column Width value (from AutoSize value);
    Disable the AutoSize Property and finally, set the Column Width to the Width value you previously stored.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 169k
  • Answers 169k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would not rely on the ThreadPool ever resetting information,… May 12, 2026 at 1:54 pm
  • Editorial Team
    Editorial Team added an answer wrapInner() is what you're after I think $("#description").wrapInner('<p></p>'); will result… May 12, 2026 at 1:54 pm
  • Editorial Team
    Editorial Team added an answer Is it because the "=" on the line s.t =… May 12, 2026 at 1:54 pm

Related Questions

Hi I need a quick solution to do filtering/sorting using the Winforms DataGridView control
I have an XML file: <SMS> <Number>+447761692278</Number> <DateTime>2009-07-27T15:20:32</DateTime> <Message>Yes</Message> <FollowedUpBy>Unassigned</FollowedUpBy> <Outcome></Outcome> <Quantity>0</Quantity> <Points>0</Points> </SMS>
I am populating a textfield programmatically and scrolling to the maxScrollH as the new
I have a Drupal module page where I am populating a form with a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.