gpt4 book ai didi

c# - 将 BindingSource.DataSource 声明为通用的

转载 作者:行者123 更新时间:2023-11-30 15:54:49 26 4
gpt4 key购买 nike

我正在尝试将 bindingSource 声明为通用控件中的通用

public partial class ABMControl<T> : UserControl
{
public ABMControl()
{
InitializeComponent();
}
}
partial class ABMControl<T>
{
...
private void InitializeComponent()
{
...
this.bindingSource.DataSource = typeof(T)
...
}
...
}

但在设计器中这是问题所在:

Failed to parse method 'InitializeComponent'. The parser reported the following error 'Type parameters are not suppported Parameter name: typeSymbol'. Please look in the Task List for potential errors.

But in the designer this is the problem

最佳答案

为防止设计者出错,在构造函数中设置绑定(bind)源的数据源。

当您将一段代码放入控件设计器的构造函数中时,解串器将不会尝试解析它。它也不会在您的控件的设计时运行,而在运行时和派生控件中,它会运行。

以下是防止错误的必要条件:

public partial class ABMControl<T> : UserControl
{
public ABMControl()
{
InitializeComponent();
this.bindingSource.DataSource = typeof(T)
}
}

有关设计器如何工作的更多信息,请查看以下帖子,特别查看包含一些错误但显示设计器的示例:

关于c# - 将 BindingSource.DataSource 声明为通用的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49459161/

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