Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
193 views
in Technique[技术] by (71.8m points)

c# - How to make other controls see a collection of DataTables in a custom control?

I am building a custom compoment that can be dragged from the toolbox onto a form.
It exposes a List of type DataTable, and this works well so far.

What I am missing is that when I put a BindingSource on the same form, in the designer the BindingSource does not see my collection of DataTables. So I cannot select one of the DataTables from the custom component. I know I can do this in code but that is not the idea, I want to do it in the designer.

How can I accomplish this ?

The code for the public collection of DataTables is this

[Serializable]
public partial class gttDataModule : Component
{
    private List<DataTable> _dataTables = new List<DataTable>();


    public List<DataTable> DataTables
    {
        get { return _dataTables; }
        set { _dataTables = value; }
    }

The collection of DataTables is populated and filled with columns and everything, see also the attached image.
Everything works except that BindingSources and other controls that can accept a DataTable as DataSource do not see this collection.
Is there a way to accomplish this ?

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Please click DataSource-> Other Data Sources->List Instances-> choose the datatable you added in the custom control to set the datasource for bindingSouce control.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...