Reputation: 7919
In Windows Forms I used:
dataGridView.DataSource = new BindingList<MyItem>();
The equivalent in WPF seems to be:
dataGrid.ItemsSource = new BindingList<MyItem>();
What I don't understand (and perhaps I'm doing something wrong) is that in the WPF case, the binding doesn't seem to be bidirectional. That is to say: when I modify a MyItem
, it is not automatically reflected in the view.
Upvotes: 0
Views: 34
Reputation: 37066
Use ObservableCollection<MyItem>
.
MyItem
must implement INotifyPropertyChanged
and raise PropertyChanged
when any of its property values changes.
That'll update the grid cells.
Binding
. Assigning a collection to a property doesn't bind it. XAML:
<DataGrid
x:Name="dataGrid"
ItemsSource="{Binding MyItemCollection}"
...
/>
You can also create a Binding programmatically, if you really want to make a lot of extra work for yourself.
Seems like ObservableCollection has some improvements over BindingList.
Upvotes: 1