- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
You need to separate your model (data structure) from your logic and from your view (your form)
Example (C#) :
public class Model()
{
public string property (get; set;)
}
public class ViewModel()
{
public BindingList<Model> myBindingList = new BindingList<Model>();
myBindingList.add( new Model
{
property = "this property",
});
{
public partial class View : Form
{
public View(BindingList<Model> bindingList)
{
// Let say you have set a DataGridView in your Form Designer
InitializeComponent();
BindingSource bindingSource = new BindingSource(bindingList, "")
dataGridView1.DataSource = BindingSource;
}
}
In your ViewModel Class, you can subscribe your events and do all your logics. You should place as little code as possible in your forms.
In a way, You should try to setup a MVVM structure you would do in a WPF form.
This way, you never have properties and method in a form.