刚才我遇到了这个奇怪的问题,我想知道是否有我在 VS2012 中遗漏的东西来解决它。我正在使用 MDI Windows 窗体,我有这个 dataGridView
,我从数据库中检索数据,然后使用数据库中的数据设置网格的 dataSource
属性。但是即使我使用一个旧项目作为这个项目的脚手架,现在我得到了 VS2012 中设计的 dataGridView
并且在它旁边我从数据库中获取数据,就好像它是我的一部分 dataGridView
设计,除了标题列是来自数据库的列名。
但是我做了一些研究,发现实际上这个问题很容易通过将 AutoGenerateColumns
属性设置为 false 来解决。我在 VS2012 设计器中找不到这个属性。现在我正在使用这个:
dgvClients.AutoGenerateColumns = false;
dgvClients.DataSource = mainGridInfoList;
在 load
事件中,但我宁愿使用设计器(当然如果可能的话)并删除这一行 - dgvClients.AutoGenerateColumns = false;
从我的代码。问题是我看不到 dataGridView
的确切名称的属性,所以我想知道 - 名称是否已更改?这有点奇怪,因为我仍然可以在我的代码中使用它,或者 IDE 设计器从来没有办法做到这一点,它必须明确地写在源代码中?
附言
对于这个特定问题,使用 IDE 设计器并不是很好的决定(至少我这么认为),但这里有一个打印屏幕,可以向您展示如何从 VS2012 设计器设置此属性。
最佳答案
我在文档中找到了一些可能对您的问题有所帮助的内容。
来自 DataGridView.AutoGenerateColumns Property :
Note:
Setting the DataSource in the Windows Forms Designer automatically sets the AutoGenerateColumns property to false and generates code to add and bind a column for each property in the data source. The code that is generated at design-time is equivalent to the manually added code shown in the following example. It is not the same as the auto-generation of columns at run-time that occurs when the AutoGenerateColumns property is set to true.
关于c# - 从 VS 2012 设置 AutoGenerateColumns 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18157192/