I have form with a ListBox
and ComboBox
Both are filled with values using their .DataSource
property from the same array
public partial class Form1 : Form
{
static readonly Random rng = new Random();
public Form1()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
int[] list = Enumerable.Range(0, 20).Select((i) => rng.Next(501)).ToArray();
listBox1.DataSource = list;
comboBox1.DataSource = list;
}
}
No other code is added to my form. But when I run the form and select an item from the ListBox, the ComboBox also gets the same item selected. This works vice-versa also.
How is this black magic happening? How is the ComboBox receiving events or updates to the data binding when the ListBox is manipulated from the UI?