I have a List<> object in my main form file (Form1.cs), and I want to use data from this object in an other class.
I'm making a custom control (added a new UserControl class), it has a ComboBox which I want to be filled with names from that list, and I want it to be filled without passing it when creating that control in my main form.
In other words I want all the actions regarding my custom control to be in my UserControl class, so when I create the control in my main form it already has a ComboBox filled with the names from the list. And when a user changes the selection there's a label that will be changed in that control.
Main Form -
namespace Shibutz
{
public partial class Form1 : Form
{
//I want to use these lists in the UserControl class
List<Person> persons = new List<Person>();
List<Conditions> conditions = new List<Conditions>();
List<Missions> missions = new List<Missions>();
Tools tools = new Tools();
public Form1()
{
InitializeComponent();
}
UserControl class-
namespace Shibutz
{
public partial class CellUI : UserControl
{
public CellUI()
{
InitializeComponent();
}
//Here I want to get the List<Person> object, and fill a ComboBox
// like - cbCellPersonsList.Add(*all the items in persons from the main form*);
private void cbCellPersonsList_SelectedIndexChanged(object sender, EventArgs e)
{
//when index changes, change Label lblPersonName in the cusom control
}
}
How do I do it?