DataGrid with AutoGenerateColumns="True" and a TemplateSelector for the Cells

Jan 23, 2009 at 8:41 AM
Hello,

I'm study the DataGrid-Control.

I want to let the DataGrid generate the Columns, but I want set the Cell-TemplateSelector (for changing the way of the presentation)!

Now I wrote this:
<dg:DataGrid x:Name="dg1" ItemsSource="{Binding Path=Values, Converter={StaticResource documentItemConverter}}"
                     CanUserAddRows="False" CanUserDeleteRows="False"
                     AlternatingRowBackground="WhiteSmoke" HorizontalGridLinesBrush="Silver" VerticalGridLinesBrush="Silver"
                     GridLinesVisibility="Vertical" IsReadOnly="True"  
                     AutoGenerateColumns="True"
            >
        </dg:DataGrid>


I tried almost every possible way to do something like this:
<dg:DataGrid x:Name="dg1" ItemsSource="{Binding Path=Values, Converter={StaticResource documentItemConverter}}"
                     CanUserAddRows="False" CanUserDeleteRows="False"
                     AlternatingRowBackground="WhiteSmoke" HorizontalGridLinesBrush="Silver" VerticalGridLinesBrush="Silver"
                     GridLinesVisibility="Vertical" IsReadOnly="True"  
                     AutoGenerateColumns="True"
                    
CellTemplateSelector="{DynamicResource TemplateSelector}"
            >
        </dg:DataGrid>


Does anybody knows how to do this?
Coordinator
Jan 26, 2009 at 12:33 PM
You can listen to the DataGrid.AutoGeneratingColumn event (I believe that's the correct name).  In the event, each generated column is returned to you to modify before it is set on the DataGrid.
Jan 27, 2009 at 7:59 AM
OK, not the way I thought, but is a way!
thanks a lot!