I am just curious why the Windows DataGridView control is hiding its AutoGenerateColumns property from the designer?
Really can’t come up with some nice answer to this question.
Anyone?
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.
It looks like it’s hidden because it’s controlled by a helper class. According to the accepted answer to this question, the Initialize() method of the DataGridViewDesigner (an undocumented and pretty well-hidden helper class) sets the DGV’s AutoGenerateColumns property based on whether there is a DataSource specified, which overrides anything you might specify in your own code.
The logic would be that a DataSource is required in order to auto-generate columns; so, it would be invalid to let you try to set this property to True without having specified one. Conversely, if you’re setting the DataSource in the designer, you probably want the DGV to set up the columns for you unless you’ve also set up your own using the Columns property.
You can expose this property by overriding it in a derived class and specifying a
[Browseable(true)]attribute. However, as the question above shows, anything you set it to in a constructor or InitializeComponent() method will be overwritten by the DGVDesigner anyway.