gpt4 book ai didi

C# DataGridView,不保存列编辑器中的自定义属性

转载 作者:太空宇宙 更新时间:2023-11-03 11:18:03 33 4
gpt4 key购买 nike

我的表单中有一个数据 GridView 。此 datagridview 有一些列。有一些自定义列(我创建了自定义 datagridview 单元格)。这些自定义单元格有一些我想在设计时从 datagridview 的列编辑器中看到的属性,以便设置它们。因此在设计时,我打开了 datagridview 的列编辑器,并创建了自定义 datagridview 单元格的列。然后,我设置了一些自定义属性并关闭了 datagridview 的列编辑器。当我打开 datagridview 的列编辑器时,我之前为这些自定义属性设置的值没有反射(reflect)出来,似乎在 datagridview 的列编辑器关闭后它们没有保存。所以为什么?为什么不保存自定义属性的值?我做错了什么?

此外,我不能将这些自定义属性保留为空,因为在加载表单后我引发了异常(对象引用未设置为对象的实例)。

如果有人能帮助我,我将不胜感激。

最佳答案

我遇到了同样的问题。搜索之后,我在一个微软网站上发现了一些反馈,说我必须在我的 datagridviewtextboxcolumn 派生中实现 iCloneable

您可以找到文章 here和相关部分:

In some rare cases, the column type may want to expose a property that has no equivalent property at the cell level. Examples of that are DataGridViewLinkColumn.Text and DataGridViewImageColumn.Image. In those cases, the column class needs to override the Clone method to copy over that property.

我的专栏添加了四个额外的属性,这是我的可克隆功能:

      //Override this method to set the custom properties.
public override object Clone()
{
var col = base.Clone() as BauerDataGridViewTextBoxColumn;
col.ShowBorder = this.ShowBorder;
col.BorderColor = this.BorderColor;
col.ColumnChooserIsOptional = this.ColumnChooserIsOptional;
col.ColumnChooserColumnLabel = this.ColumnChooserColumnLabel;
return col;
}

关于C# DataGridView,不保存列编辑器中的自定义属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11992024/

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