Link to home
Start Free TrialLog in
Avatar of emi_sastra
emi_sastra

asked on

Allow user to hide and show datagridview columns

Hi All,

How could I achieve it ?

Thank you.
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

The DataGridView does not do this natively, but you can toggle the Visible property of a Column like this:

YourDataGridView.Columns(0).Visible = False

You can also refer to the column by the Column Name:

YourDataGridView.Columns("CustomerName").Visible = False

Note this is the Column Name, which may or may not be the same as the value in the Header Text.

As far as the UI methods used, I've often included a "setup" section where the user could choose which Columns to show or hide. Essentially that was a Checked List Box, or something like that, with the names of the Columns. I check them all by default and allows the user to uncheck them to hide the columns. I often do this on a Tab control, with the grid on the first tab and the Setup stuff on a different tab.
Avatar of emi_sastra
emi_sastra

ASKER

Hi Scott,

How could I save it and restore the latest state of it ?

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Scott,

Great. I get some idea.

I will try it.

Thank you very much for your help.