0

I have a datagrid with a combobox column. I want to bind this column to a list of items that I generate dynamically in the code-behind file. All rows of the datagrid will have the same list of items in the combobox column. I have done static binding using ObjectDataProvider, but I am not sure how to do this dynamically.

Any help is greatly appreciated!

Thank you, Santosh

  • What do you mean by dynamically? – H.B. Apr 30 '11 at 19:55
  • By dynamically, I mean to create items for the combobox column from a database table. These items should be the same for all rows of the datagrid and must also be available for the user to select when adding a new row to the datagrid. Currently, I am able to provide static data using ObjectDataProvider. – Santosh Jagtap Apr 30 '11 at 21:38
  • Check this question/answer: http://stackoverflow.com/questions/3562934/using-wpf-datagridcomboboxcolumn-with-mvvm-binding-to-property-in-viewmodel – joerage Jan 06 '12 at 17:34

1 Answers1

0

You can use an ObservableCollection<T> for your items, if you then bind the ItemsSource of the DataGrid to this collection you can dynamically items to the collection and they will also be added to the DataGrid. See the collections binding section on MSDN for more info. If this is not what you are looking for you might want to elaborate as your question still seems quite unclear (at least to me).

H.B.
  • 166,899
  • 29
  • 327
  • 400