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 6567469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:20:24+00:00 2026-05-25T14:20:24+00:00

Is it possible in a single hit to remove all columns from a datagrid?

  • 0

Is it possible in a single hit to remove all columns from a datagrid?

I know I could loop though and remove them one by one, or remove the whole thing and create it.

But it is possible to simply clear columns and leave the grid in place so users can start fresh.
i.e. put it back to its original state.

OK here is the code I have

private void PopulateGrid()
    {
        UserVGrid.AutoGenerateColumns = false;
        UserVGrid.Columns.Clear();
        List<string> _values = populate.GetVaribles;
        foreach (var line in _values)
        {
            if (!line.Contains("Startind"))
            {
                string[] newline = line.Split('=');
                DataGridViewColumn newColumn = new DataGridViewTextBoxColumn(); 
                newColumn.Name = newline[0]; 
                newColumn.HeaderText = newline[1]; 
                newColumn.ToolTipText = newline[2]; 
                UserVGrid.Columns.Add(newColumn); 

            }
        }

so lets assume _values has apple, pear as values

running this method once and i get a datagrid with two colums named apple and pear.

running it a second time this time with _values containg char , table.
And i end up with 4 colums apple, pear, chair and table. What I want is the second time it is run it clears the grid fist and then applied the new colums.

Cheers

Aaron

  • 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-25T14:20:25+00:00Added an answer on May 25, 2026 at 2:20 pm

    The DataGridView columns collection has a Clear() method.

    dataGridView1.Columns.Clear();
    

    This doesn’t work with a bound datagridview and autogenerated columns – in that case simply replace the datasource with null or with an empty datasource:

    dataGridView1.DataSource = null;
    

    or turn off autogeneration and create the columns in code:

    dataGridView1.AutoGenerateColumns = false;
    DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn();
    dataGridView1.Columns.Add(col);
    

    These manually generated columns will be removed by the Clear() method.

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

Sidebar

Related Questions

Is it possible to delete a single message from a MSMQ message queue ?
Is it possible to extract a single file or diff of a file from
Is it possible to have a single listview with 2 or more columns, operable
Is it possible to use single XML file for Ruby on Rails as an
It is not possible to check out a single file. The finest level of
Is it possible to copy a single file to multiple directories using the cp
Is it possible to share a single 'god' instance among everyone that links to
Is that possible to have a single PHP SOAP server which will handle requests
Is it possible to create a single .svc file (WCF Service) that I can
Is it possible to return a single value and an enumerable collection using LINQ

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.