What you need to do is perform 2 way data binding to your the ItemsSource, this way when the ItemSource is updated in one of the combo boxes it will auto update your original collection and therefore your other combo boxes as well.
Up vote 2 down vote favorite 1 share g+ share fb share tw.
Ok. This is a tricky one: (for me at least) I have a datagrid. A column of the datagrid is a simple with its CellTemplate containing a which contains a All is working fine.
Each combobox is bound to a static list - I know this because I told it to do so in the ItemsSource="{Binding Source={StaticResource resFoodLookups}}" statement. But my requirement is that this list will change from row-to-row. That is: each time a user types a new entry in the combobox list on one row, I want to have it available in the selection on the next row.
Basically, I want to create a new list for the user each time the user inserts a new word in the combobox on any of the rows. (The combobox is editable). Now, I can wire up the "ItemsSource=..." at run-time, but I'm only able to do this once thus the propagates the 'same' list to 'all' the comboboxes on 'all' the rows.
My thoughts are that I need to change the ItemsSource=... property on an object-by-object basis on each combobox that is created in memory after the DataTemplae has created them - but I have no idea how to do this!?! Can anyone help or at least point me in the right direction? Thanks... ** wpf data-binding datagrid combobox link|improve this question asked Feb 26 '10 at 4:41user281794485 20% accept rate.
What you need to do is perform 2 way data binding to your the ItemsSource, this way when the ItemSource is updated in one of the combo boxes it will auto update your original collection and therefore your other combo boxes as well. Edit What I normally do is use the MVVM pattern. It is worth some research if you are not already using a particular pattern on your application.
Using it to solve your problem I would do the following: Create a ViewModel (Lets call it MyViewModel) which has a collection of values called 'MyComboBoxItems' (It is important that you use ObservableCollection for the databinding to work) When I create the Window/Control that contains your table, I also create an instance of MyViewModel and set its the Window. DataContext=myViewModelInstance For your combobox binding use ItemsSource="{Binding Path=MyComboBoxItems, Mode=TwoWay}.
Yes, OK. This seems like a solution, but how do I set the combobox's ItemsSource property? At run-time, I can set the ItemsSource property on other comboboxes in code with no problems.
E.g. MyComboBox1. ItemsSource = _myListOfStrings; myComboBox2.
ItemsSource = App.DataLayer.GetUniqueFoods(); But I cant seem to 'get at' the combo box that resides in the datagrid's DataTemplate. Something like: ((DataGridTemplateColumn)dataGridMain. Columns0).CellTemplate.DataTemplate.
Comb?oDataTemplate. ItemsSource = ; (I know this is wrong - but you get my meaning? ) – user281794 Feb 26 '10 at 5:54 If I set the ItemsSource property of the combobox at build-time (with XAML), how can I 'load' my initial object with data?
Maybe I'm over-complicating things? – user281794 Feb 26 '10 at 5:55 If the 'MyComboBoxItems' observable collection gets sorted, or an item gets deleted, the combobox entries disappear. I think that the databinding gets screwed up here.
Can you suggest a way around this at all? – user281794 Mar 4 '10 at 20:09 Jack could you give me some more details of your current problem? Is the databinding working at all now?
– Leigh S Mar 4 '10 at 22:53 Thanks Leigh. Yes, I got it working with your help. – user281794 Mar 7 '10 at 16:50.
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.