DataGrid No Header & Access Template Content from code

Apr 21, 2009 at 3:51 PM
Hi,

I have two questions:
1.I can't see the header text when running the following xaml code:

                <dg:DataGrid
                    Name="grdEmp"
                    Width="498px"
                    Height="146px"
                    Margin="15px,19px,0,0"                    
                    AutoGenerateColumns="False"
                    HeadersVisibility="Column"
                    ItemsSource="{Binding Path=Emp.DefaultView}">
                    
                    <dg:DataGrid.Columns>
                        
                    <dg:DataGridTemplateColumn x:Name="empno" IsReadOnly="True"  Header="No." Width="32" MinWidth="32" SortMemberPath="Empno" Visibility="Visible" CanUserReorder="False">
                        <dg:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Path=Empno}" TextAlignment="Right" />
                            </DataTemplate>
                        </dg:DataGridTemplateColumn.CellTemplate>
                        <dg:DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <TextBox Text="{Binding Path=Empno}"/>
                            </DataTemplate>
                        </dg:DataGridTemplateColumn.CellEditingTemplate>
                    </dg:DataGridTemplateColumn>
...


2. How can i access the Textbox located inside the CellEditingTemplate from code behind ?

Thanks in advance.

Rui G.

Jun 25, 2009 at 2:31 PM

I think I may be having the same problem - setting HeadersVisibility="Column" or HeadersVisibility="None" causes the data rows to overwrite the column headers (you can still see just the top few pixels of them). Even after setting ColumnHeaderHeight="200", the view is identical.

Interestingly, the headers are still there and may be re-ordered or sorted, and when re-ordering them they become temporarily fully visible, the rest of the datagrid shifting down to accomodate.

Any thoughts?

Jun 25, 2009 at 4:06 PM

This appears to have been caused by setting a style using <font size="2" color="#ff0000"><font size="2" color="#ff0000">

x

</font></font><font size="2" color="#ff0000">

 

</font>

:Key="dataGridStyle"

If the style is set without this, HeadersVisibiliy="Column" works as expected.