Home > Software design >  Cannot select List as a data source in C# visual studio designer
Cannot select List as a data source in C# visual studio designer

Time:07-09

I have a WinForm with a Listbox, and a class which contains a List I want to use for a data source.

DataSource property for the Listbox wont give me the option for the List I want to use. I know I cannot add this list to the DataSource through designer.cs as its generated and the line just disappears, but..

If I add this to designer.cs it works, until the code disappears:

`this.listbox1.DataSource = Namespace1.MyWinform.MyList.ToArray();`

Only looks like I have no choice but to use the designer properties. How may I achieve this?

Thanks.

CodePudding user response:

As Chetan's comment suggests,the solution is to add the code into the "form_load":

private void Form1_Load(object sender, EventArgs e)
        {
            this.listbox1.DataSource = Namespace1.MyWinform.MyList.ToArray();
        }
  • Related