0

I have a DataGrid dg; and I would like to display a DataGridComboBoxColumn with data populated from some list (using binding). Using XAML I have dg.ItemsSource properly set but I do not know, how to set the column's ItemsSource:

<DataGridComboBoxColumn ItemsSource={?????????} />

James

Cartesius00
  • 23,584
  • 43
  • 124
  • 195

2 Answers2

1
<DataGridComboBoxColumn ItemsSource="{Binding AvailableOptions}" />

Here, AvailableOptions is a property of a data item bound to the grid row. This property should contain a list of options available in the combo box.

Update:

If the collection of options to select from is fixed you could use ObjectDataProvider defined in resources. See http://blogs.ugidotnet.org/ccavalli/archive/2006/02/09/34592.aspx for example.

In your case it could be something like this:

<ObjectDataProvider x:Key="Options" ObjectType="{x:Type my:MyOptions}"  />

-

<DataGridComboBoxColumn ItemsSource="{Binding Source={StaticResource Options}}" />
Pavlo Glazkov
  • 20,498
  • 3
  • 58
  • 71
  • No, that's not so simple because I'd like to populate this column (each row) with some fixed Collection and I do not have direct access to it. I need somehow change context but I do not know how. – Cartesius00 May 25 '11 at 09:43
1

You can use the datacontext to get the property you are tying to bind to your DataGridComboBoxColumn.Check the below post

Binding a WPF DataGridComboBoxColumn with MVVM

Community
  • 1
  • 1
biju
  • 17,554
  • 10
  • 59
  • 95