其他分享
首页 > 其他分享> > 从VS 2012设置AutoGenerateColumns属性

从VS 2012设置AutoGenerateColumns属性

作者:互联网

刚才我遇到了一个奇怪的问题,我想知道在VS2012中是否有我想解决的问题.我正在使用MDI Windows窗体,并且具有这个dataGridView,我从数据库中检索数据,然后使用来自数据库的数据设置网格的dataSource属性.但是,即使我使用一个旧项目作为该项目的支架,现在我也可以像在VS2012中设计的那样获得dataGridView,然后在其旁边我从数据库中获取数据,就好像它是我的dataGridView设计的一部分一样,但标题列与数据库中列的名称.

但是,我进行了一些研究,发现实际上可以通过将AutoGenerateColumns属性设置为false轻松解决此问题.我找不到的是VS2012设计器中的此属性.现在我正在使用这个:

        dgvClients.AutoGenerateColumns = false;
        dgvClients.DataSource = mainGridInfoList;

在加载事件中,但我宁愿使用设计器(如果可能的话)并删除此行-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.

标签:visual-studio-2012,c,net,winforms
来源: https://codeday.me/bug/20191030/1968790.html