I have a DataGridView form in my .NET application and I’d like to be able to show or hide additional columns based on a Boolean value at run time.
What’s the best way to show/hide these columns in code (as opposed to in the Forms Designer)?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
The easiest option (if the columns are known ahead of time) is to add them as you would normally, then set
Visibleas appropriate (on each) at runtime.You can also add extra columns completely at runtime (if you can’t predict the schema) – but note that this might work differently depending on whether you are using data-binding (i.e. a
DataSource).