Hot to bind collection to DataGridComboBoxColumn?

Nov 11, 2008 at 4:53 PM
Edited Nov 11, 2008 at 4:56 PM

I want to bind DataGrid to collection of objects which have a field of type ObservableCollection<string> (Subs) which I would like to bind to DataGridComboBoxColumn

        <my:DataGrid Margin="8,9,6,69" Name="filmsGrid" AutoGenerateColumns="False" >
                <my:DataGridComboBoxColumn ItemsSource="{Binding Path=Subs, Converter={StaticResource TestConverter}}" ></my:DataGridComboBoxColumn>

The strange thing is that data are not going to ItemsSource (my TestConverter Convert method is not triggered).

I also tried to use DataGridTemplateColumn like this:

        <DataTemplate x:Key="ComboTemplate">

            <ComboBox   ItemsSource="{Binding Path=Subs, Mode=OneTime, Converter={StaticResource TestConverter}}" ></ComboBox>


I works almost because even with Mode set to OneTime the ItemSource is set when I’m scrolling a grid (binding is refreshed and selection on comboboxes is cleared).


Any ideas on how to simply bind this collection to ComboBox one time??

Nov 12, 2008 at 1:38 PM
Using a DataGridTemplateColumn should work.  Here's an example where ColorItem and ColorItems are just arbitrary objects:



g:DataGridTemplateColumn Header="ColorItem">
            <TextBlock Text="{Binding Path=ColorItem, Mode=OneWay}" />
            <ComboBox SelectedItem="{Binding Path=ColorItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding Path=ColorItems}"/>

Nov 14, 2008 at 8:39 PM