Make a WinForms application in Visual Studio 2010, .NET 4.0, then make a user control (from Project/Add User Control...) with this code:
public partial class UserControl1 : UserControl
{
private string _SelectedTable;
public string SelectedTable
{
get { return _SelectedTable; }
set { _SelectedTable = value; }
}
public UserControl1()
{
InitializeComponent();
DataBindings.Add("SelectedTable", listBox1, "SelectedValue");
listBox1.DataSource = new List<string>();
}
}
Compile, add the control from the tool box to Form1, compile again and try to close. It won't (right?). Why?
There are things I can do to prevent this from happening, like changing the line DataBindings.Add("SelectedTable", listBox1, "SelectedValue"); to DataBindings.Add("SelectedTable", tablesListBox, "SelectedValue", false, DataSourceUpdateMode.Never);, or removing any of the two lines after InitializeComponent(). But I would like to know why is this happening, or at least, what is in general what I'm doing wrong, the general rule I'm breaking so I don't make a similar mistake again.