Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declare BindingSource.DataSource as generic

i'm trying to declare bindingSource as generic in a control generic

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

But in the designer this is the problem:

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

like image 585
Federico Fia Sare Avatar asked Nov 24 '25 20:11

Federico Fia Sare


1 Answers

To prevent designer error, set data source of binding source in constructor.

When you put a piece of code in constructor of your control designer deserializer will not try to parse it. It also will not run in design time of your control, while in run-time and also for derived control, it will run.

Here is what you should have to prevent error:

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

For more information about how designer works take a look at the following post, specially take a look at the example which contains a couple of errors but shows the designer:

  • Can't view designer when coding a form in C#
like image 198
Reza Aghaei Avatar answered Nov 27 '25 10:11

Reza Aghaei



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!