Hot to bind collection to DataGridComboBoxColumn?

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


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:DataGrid.Columns>
                <my:DataGridComboBoxColumn ItemsSource="{Binding Path=Subs, Converter={StaticResource TestConverter}}" ></my:DataGridComboBoxColumn>
            </my:DataGrid.Columns>
        </my:DataGrid>

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>

        </DataTemplate>

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??



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

<d

 

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

Nov 14, 2008 at 8:39 PM
Tnx,