为什么DataGridView.AutoGenerateColumns应用了Browsable(false)属性? [英] Why DataGridView.AutoGenerateColumns has a Browsable(false) attribute applied?

查看:79
本文介绍了为什么DataGridView.AutoGenerateColumns应用了Browsable(false)属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇,为什么Windows DataGridView控件向设计人员隐藏了其AutoGenerateColumns属性?

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?

推荐答案

它似乎是隐藏的,因为它是由助手类控制的。根据对此问题的可接受答案,使用Initialize()方法DataGridViewDesigner的代码(一个未记录的,很好隐藏的帮助程序类)根据是否指定了DataSource来设置DGV的AutoGenerateColumns属性,该属性将覆盖您可能在自己的代码中指定的任何内容。

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.

逻辑是需要一个DataSource来自动生成列;因此,让您尝试将此属性设置为True而不指定该属性将是无效的。相反,如果要在设计器中设置数据源,则可能希望DGV为您设置列,除非您还使用Columns属性来设置自己的列。

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.

您可以通过在派生类中重写此属性并指定 [Browseable(true)] 属性来公开此属性。但是,如上面的问题所示,无论如何,在构造函数或InitializeComponent()方法中设置的任何内容都会被DGVDesigner覆盖。

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.

这篇关于为什么DataGridView.AutoGenerateColumns应用了Browsable(false)属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆