I suspect you'll need to make the SelectedItem binding update the source on PropertyChanged for this to work.
Up vote 1 down vote favorite share g+ share fb share tw.
If I set up a new WPF application in Visual Studio 2010 and add the following code+XAML, a data grid opens with comboboxes inside. The problem now is that changeing a value through a combobox does not get propagated to the bound data model. In other words: the property named MyValue never gets set.
It took me hours now and I have no clue why this doesn't work. Also many similar threads and suggestions didn't. Here the XAML.
It is just a simple Window with a DataGrid contained. The DataGrid has a template column where CellTemplate and CellEditingTemplate are set. Both contain a ComboBox that is filled with the list from the resource section.
The ComboBox. SelectedItem is bound to MyItem. MyValue: Here the code.
It contains the main Window ctor which just sets up a DataContext. MyItem is the row's datamodel supporting INotifyPropertyChanged. MyItemList is the list of choices bound to ComboBox.ItemsSource.
Public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); myDataGrid. ItemsSource = new List { new MyItem { MyValue = "i0" }, new MyItem { MyValue = "i1" }, new MyItem { MyValue = "i0" }, }; } } public class MyItem : INotifyPropertyChanged { public string MyValue { get { return myValue; } set { myValue = value; if (PropertyChanged! = null) { PropertyChanged(this, new PropertyChangedEventArgs("MyValue")); } } } private string myValue; public event PropertyChangedEventHandler PropertyChanged; } public class MyItemList : List { public MyItemList() { Add("i0"); Add("i1"); Add("i2"); } } .net wpf data-binding datagrid combobox link|improve this question edited Apr 14 '11 at 22:51 asked Apr 14 '11 at 19:47MRoc185.
I suspect you'll need to make the SelectedItem binding update the source on PropertyChanged for this to work. SelectedItem="{Binding Path=MyValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" I'd make the CellTemplate and CellEditingTemplate both reference your edit template while debugging this, to eliminate the other, irrelevant, template until you get it sorted out.
1 I just tested it out, and it worked for me. I made both CellTemplate and CellEditingTemplate reference the edit template, and added UpdateSourceTrigger=PropertyChanged. When I select an item in a combobox, the MyValue setter is invoked.
I'm testing against . NET 4.0 with VS 2010 SP1 installed. – Josh Smith Apr 14 '11 at 20:52 HEUREKA!
Now it works. Thank you very much! – MRoc Apr 14 '11 at 20:53.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.