Hi Guys,

OK, i've been through nearly all the properties possible in VS2010 to try and find how to do this most basic of tasks.

Look at Screenshot 25... This is how it shows at the moment.

Now look at Screenshot 26... This is How I WANT it too look but every property i try it does not fill to DGV!?

Any ideas?


Hi Mark,

Hope all is well.

A quick google turned up the following two possible solutions you can try:

  • DataGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
  • DataGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

Pulled them off of SO, original link here

Hi Mikey,

I've had a play and I'n not to sure how to impliment it within my code as I've never used it before...

Here is what I have so far..

  //Displays the Wanted Data in Grid View//
            dataGridView1.DataSource = ds.Tables["VPN"];

            dataGridView1.Columns["VPN_ID"].Visible = false;
            dataGridView1.Columns["companyName"].Visible = true;
            dataGridView1.Columns["vpn_IP"].Visible = false;
            dataGridView1.Columns["Domain"].Visible = false;
            dataGridView1.Columns["vpn_Username"].Visible = false;
            dataGridView1.Columns["vpn_Password"].Visible = false;

            dataGridView1.Columns["companyName"].HeaderText = "Company Name";

I haven't tried it myself either, would presume the implementation is: dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;


That's what I tried but I get the following error?

"Error 1 Cannot implicitly convert type 'System.Windows.Forms.DataGridViewAutoSizeColumnMode' to 'System.Windows.Forms.DataGridViewAutoSizeColumnsMode'. An explicit conversion exists (are you missing a cast?)"

Try just setting it in the properties window in design mode.

Note the first mention of column is singular and the second is plural. Is that mistake in the code?

Hi Mikey,

Yes and Yes.. Sorry "Blonde Moment" All sorted now. Thank you.

No worries happens to all of us!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.