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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:00:18+00:00 2026-05-22T21:00:18+00:00

I have a DataGridView filled with productinformation. The datagridview has totally 50 columns but

  • 0

I have a DataGridView filled with productinformation. The datagridview has totally 50 columns but the users don’t always need all the columns, I want to help them to be able to choose which columns to show and which ones not to show.

One solution that I would like to programm is that when the user right clicks on the columns they can choose from a list that pops up choose which columns to show and which ones not to shos. Just like the image below.
enter image description here

How can I do that. I would really appreciate any help.

  • 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-22T21:00:19+00:00Added an answer on May 22, 2026 at 9:00 pm

    You can achieve this using the WinForms ContextMenuStrip and the Visible property of DataGridView columns.

    Here is some example code that does what you want:

    namespace WindowsFormsApplication4
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
    
                BindingList<User> users = new BindingList<User>{
                      new User{Name = "John", Address="Home Street", Title="Mr."},
                      new User{Name = "Sally", Address="Home Street", Title="Mrs."}
                };
    
                contextMenuStrip1.AutoClose = true;       
                contextMenuStrip1.Closing += new ToolStripDropDownClosingEventHandler(contextMenuStrip1_Closing);
    
                dataGridView1.DataSource = users;
    
                dataGridView1.DataBindingComplete += new DataGridViewBindingCompleteEventHandler(dataGridView1_DataBindingComplete);
            }
    
            void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
            {
    
                foreach (DataGridViewColumn gridViewColumn in this.dataGridView1.Columns)
                {
                    ToolStripMenuItem item = new ToolStripMenuItem();
                    item.Name = gridViewColumn.Name;
                    item.Text = gridViewColumn.Name;
                    item.Checked = true;
                    item.CheckOnClick = true;
                    item.CheckedChanged += new EventHandler(item_CheckedChanged);
                    contextMenuStrip1.Items.Add(item);
                }
    
                foreach (DataGridViewColumn gridViewColumn in this.dataGridView1.Columns)
                {
                    gridViewColumn.HeaderCell.ContextMenuStrip = contextMenuStrip1;
                }
    
            }
    
            void item_CheckedChanged(object sender, EventArgs e)
            {
                ToolStripMenuItem item = sender as ToolStripMenuItem;
    
                if (item != null)
                {
                    dataGridView1.Columns[item.Name].Visible = item.Checked;
                }
            }
    
            void contextMenuStrip1_Closing(object sender, ToolStripDropDownClosingEventArgs e)
            {
                if (e.CloseReason == ToolStripDropDownCloseReason.ItemClicked)
                {
                    e.Cancel = true;
                }
            }
        }
    
        public class User
        {
            public string Name { get; set; }
            public string Address { get; set; }
            public string Title { get; set; }
        }
    
    }
    

    The User class there is just so the example compiles, providing something to bind my DataGridView to.

    I’ve also added some code that allows users to click more than one column at a time (by checking the close reason on closing and cancelling if it was an item select). This is actually a little borderline in terms of diverting from standard UI behaviour in my opinion – it is usually better to stick with standard behaviour, but I included since it is (I think) useful in this scenario.

    Also, it is generally tidier to put this sort of customisation into a new control that inherits from DataGridView.

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

Sidebar

Related Questions

I have datagridview with checkbox column, but I want, that some of the columns
I have a DataGridView with 5 columns, with dock = filled . I want
I have a DataGridView with four Columns and need to crate a multiline string
I have datagridview with paging enabled. But when I want to move from page
I have a datagridview with three columns which is filled using Datareader. There is
I have DataGridView which contains two ComboBox columns. The second ComboBox will be filled
I have a DataGridView that I want users to be able to add records
I have a DataGridView with all columns set to Automatic sort mode. When I
I have a datagridview where the users can select which subset of columns to
I have a datagridview filled with 8 columns of comboboxes, and 32 rows. private

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.