gpt4 book ai didi

c# - 从 VS 2012 设置 AutoGenerateColumns 属性

转载 作者:行者123 更新时间:2023-11-30 15:32:56 25 4
gpt4 key购买 nike

刚才我遇到了这个奇怪的问题,我想知道是否有我在 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 设计器设置此属性。

AutoGenerateColumn

最佳答案

我在文档中找到了一些可能对您的问题有所帮助的内容。

来自 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com