I have an object that has as one of its properties, a List. I want to bind a datagrid to that list, such that when I add objects to the grid, the datagrid updates. I tried:
myDataGrid.DataSource = myObject.MyList;
but when I update the datasource with new rows, the grid doesn't update.
Then I tried:
myDataGrid.DataSource = null;
myDataGrid.DataSource = myObject.MyList;
Calling the above code every time I added an item. This resulted in an error when clicking on the grid (specifically, index -1 has no data, something to do with the datagridview.get_current internally. Happens despite the fact that I'm not clicking the -1st row).
So then I tried:
myDataGrid.DataBindings.Add(new Binding("DataSoruce",myObject,"MyList",false,DataSourceUpdateMode.OnPropertyChanged));
That didn't reflect the updates either, so I added:
myDataGrid.DataBindings[0].ReadValue();
whenever I added an item, but it has no effect either. I feel like I'm circling around a simpler solution to this problem, but I can't seem to find it. Any pro tips?