I have created a custom Component, derived from BindingSource and it seems to work as expected.
When I drop it on a Form, I can set all properties and other controls see it and can use it as datasource for binding. This all works well.
My problem is, when I want to access this component in code, the code editor keeps telling me there is no such component.
How is that possible ?
It shows in the designer, I can set properties, I can let it interact with other controls in the Designer and at runtime it works perfect.
But the code editor cannot find it, it keeps saying:
The name gttDatasource1" does not exists in the current context
What can cause this? How to fix it?
I tried clean/rebuild
I tried restarting VS
I tried restarting the computer
EDIT
Part of the Designer.cs of the Form I dropped the component on:
namespace Test_app
{
partial class FormLogSCSSalesInvoiceList
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormLogSCSSalesInvoiceList));
gttControls.gttDataSource gttDataSource1 = new gttControls.gttDataSource();
The custom component is in the Designer.cs
Part of the code of the custom component
namespace gttControls
{
internal class gttDataSourceCodeDomSerializer : CodeDomSerializer
{
public override object Deserialize(IDesignerSerializationManager manager, object codeObject)
{
CodeDomSerializer baseClassSerializer = (CodeDomSerializer)manager.GetSerializer(typeof(gttDataSource).BaseType, typeof(CodeDomSerializer));
var Result = baseClassSerializer.Deserialize(manager, codeObject);
((gttDataSource)Result).CorrectTableColumns();
return Result;
}
}
public delegate void OnActiveChangedHandler(object sender, EventArgs e);
public delegate void OnBeforeUpdateHandler(object sender, EventArgs e);
[DesignerSerializer(typeof(gttDataSourceCodeDomSerializer), typeof(CodeDomSerializer))]
public partial class gttDataSource : BindingSource
{
private readonly gttDataTable _gttDataTable;
private GttTableProperties _gttTableProperties;
private Collection<gttDataTableColumn> _columns = new Collection<gttDataTableColumn>();
private bool _active = false;
private readonly bool _refreshSchema = false;
public event ActiveChangedHandler ActiveChanged;
public event BeforeUpdateHandler BeforeUpdate;
public gttDataSource()
{
_gttTableProperties = new GttTableProperties(this);
_gttDataTable = new gttDataTable();
DataSource = _gttDataTable.Table;
_gttDataTable.BeforeUpdate += _gttDataTable_BeforeUpdate;
}
}
}
EDIT 2
When I try to use this Component in code I get this:
And to proof the Component is actually in the Form's Designer:
EDIT 3
I added a ctor as suggested in the comments:
public gttDataSource(IContainer container) : this()
{
if (container == null)
{
throw new ArgumentNullException("container is null");
}
container.Add(this);
}
But it does not help. This constructor does not gets called when dropping the component on the form, or at any other time.

