This is a migrated thread and some comments may be shown as answers.

How to find/access controls in .cs (code behind file) which are added in <Tele:GridViewColumnGroup.HeaderTemplate

6 Answers 306 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Laxman
Top achievements
Rank 1
Laxman asked on 31 Aug 2012, 12:51 PM
The following is the Markup. 

<Grid Grid.Row="4" Grid.Column="0" >
            <Grid.RowDefinitions>
                <RowDefinition Height="*"></RowDefinition>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"></ColumnDefinition>
            </Grid.ColumnDefinitions>
                          <!--RadGridView for View Workforce Plan-->
            <Tele:RadGridView Name="RgvViewWorkforcePlan" GridLinesVisibility="Both" IsReadOnly="True" AutoGenerateColumns="False" VerticalAlignment="Stretch"
                              CanUserFreezeColumns="False" ShowGroupPanel="False" RowIndicatorVisibility="Collapsed" Width="Auto"
                              ScrollViewer.VerticalScrollBarVisibility="auto"  ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="auto" SnapsToDevicePixels="False" VerticalContentAlignment="Top"
                              ItemsSource="{Binding TempGridData,Mode=OneWay}" CanUserResizeColumns="False"   SelectionMode="Single" SelectionUnit="FullRow" SelectedItem="{Binding SelectedGridItem,Mode=TwoWay}"
                              Background="#EAF3FC">
                <!--It creates a column group in which we can merge column headers as needed-->
                    <Tele:RadGridView.ColumnGroups>
                        <Tele:GridViewColumnGroup Name="MonthName">
                            <Tele:GridViewColumnGroup.HeaderTemplate>
                                <DataTemplate>
                                    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="#EAF3FC" >
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="23"></RowDefinition>
                                        </Grid.RowDefinitions>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*"></ColumnDefinition>
                                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                                        </Grid.ColumnDefinitions>
                                        <Label  Name="lblMonthName"  Grid.Row="0" Grid.Column="0" Content="August - 2012" HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" Padding="0.3" ></Label>
                                         <StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Stretch" Width="Auto">
                                            <Button Name="btnFirst" HorizontalAlignment="Center" VerticalAlignment="Center" Content="&lt;&lt;"/>
                                            <Button Name="btnPrevious" HorizontalAlignment="Center" VerticalAlignment="Center" Content="&lt;"/>
                                            <Button Name="btnNext" HorizontalAlignment="Center" VerticalAlignment="Center" Content="&gt;" Click="btnNext_Click"/>
                                            <Button Name="btnLast" HorizontalAlignment="Center" VerticalAlignment="Center" Content="&gt;&gt;"/>
                                        </StackPanel>
                                    </Grid>
                                </DataTemplate>
                            </Tele:GridViewColumnGroup.HeaderTemplate>
                        </Tele:GridViewColumnGroup> 
                       
                    </Tele:RadGridView.ColumnGroups>
                        <Tele:RadGridView.Columns>
                          <Tele:GridViewDataColumn Header=""   HeaderCellStyle="{StaticResource GridDropHeaderCell}">
                            <!--<Tele:GridViewColumn.Header>
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="30"></RowDefinition>
                                    </Grid.RowDefinitions> 
                                    <Button Grid.Row="0" Grid.Column="0" Content="test Button" ></Button>
                                </Grid>
                            </Tele:GridViewColumn.Header>-->
                                <Tele:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Tele:RadButton Name="BtnDeleteComponent" Width="21" Style="{StaticResource GridButton}" ToolTip="Delete" VerticalAlignment="Top" HorizontalAlignment="Center" Grid.Row="0" Grid.Column="0" Margin="0,1,0,0" Background="Transparent" Height="21" Padding="0" Foreground="Transparent" BorderBrush="Transparent" BorderThickness="0" DataContext="{Binding componentCode}">
                                    <Image Name="ImgSearchGenCode" Source="Images\DeleteButton.png" Width="21" Height="21" Cursor="Hand"  OpacityMask="#D3E6FF" AllowDrop="False" HorizontalAlignment="Center" VerticalAlignment="Top"></Image>
                                </Tele:RadButton>
                            </DataTemplate>
                        </Tele:GridViewColumn.CellTemplate>
                    </Tele:GridViewDataColumn>
                    <Tele:GridViewDataColumn Header="Job Type" DataMemberBinding="{Binding jobType,Mode=OneWay}"  HeaderCellStyle="{StaticResource GridDropHeaderCell}">
                    </Tele:GridViewDataColumn>
                    <Tele:GridViewDataColumn Header="Branch/Gen" DataMemberBinding="{Binding branchGeneratorCode,Mode=OneWay}" HeaderCellStyle="{StaticResource GridDropHeaderCell}" Width="80">
                    </Tele:GridViewDataColumn>
                    <Tele:GridViewDataColumn Header="Custom Data field TBD" DataMemberBinding="{Binding customDataField,Mode=OneWay}" HeaderCellStyle="{StaticResource GridDropHeaderCell}" Width="132"  >
                    </Tele:GridViewDataColumn>
</<Tele:RadGridView>
 <Grid>
In the above markup I added a Label control, Panel and controls in GridViewColumnGroup.HeaderTemplate. In  the Panel added 4 buttons. My issue is I can't able to find those control which are added in GridViewColumnGroup.HeaderTemplate in code behind .cs file. I need to update the Label content and set the button enable and disable as per business requirement.  

Please help me to resolve this issue.

one more issue I have is I am adding columns in the grid at run time and assigning those column ColumGroupName="MonthName" which I set in Markup but first time it work fine when and sets a comon Column Group Header. I click on next button I am creating some more columns again in the grid and adding with same  ColumGroupName="MonthName" in that case, for next time dynamically added columns the ColumnGroupName is not working so It is not putting next time dynamically added column in the same Colum Group Header.

Waiting for your quick response.

Thanks
Laxman


6 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 03 Sep 2012, 10:22 AM
Hello,

You can access the controls inside the HeaderTemplate as follows: 
var groups = clubsGrid.ColumnGroups.Where(t => t.Name == "MonthName");
if (groups.ToList().Count > 0)
{
GridViewColumnGroup group = groups.FirstOrDefault();
var template = group.HeaderTemplate.LoadContent();
var button = template.ChildrenOfType<Button>().Where(t => t.Name == "btnFirst");
}

As to the issue you have, may I ask you whether you have tested with the latest version?

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Laxman
Top achievements
Rank 1
answered on 03 Sep 2012, 11:20 AM
Hi Support Team,

It does not work for me. I am using the following telerik controls version in WPF.
Version is:  2011.3.1220
Please assist me how to solve this issue and which version you want me to use?

Thanks

Laxman.
0
Dimitrina
Telerik team
answered on 03 Sep 2012, 12:39 PM
Hi,

 I have tested with version "2011.3.1220" and I get the instance of the "btnFirst" button. You just need to change the last line like so:

var button = template.ChildrenOfType<Button>().Where(t => t.Name == "btnFirst").FirstOrDefault();

By the latest version I meant version Q2 2012 Service Pack.

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Laxman
Top achievements
Rank 1
answered on 03 Sep 2012, 12:55 PM
Hi Support Team,

Thanks a lot for your quick response.
 
I am can get the Button and Label instance now but When I change its Content property, it is not updating in the User Interface. Please assist me.

Thanks

Laxman
0
Accepted
Dimitrina
Telerik team
answered on 04 Sep 2012, 07:49 AM
Hi,

This cannot be changed in code behind, but you can use Binding for the Content Property and bind it to a property defined in a ViewModel. You can use a StaticResource to specify the correct source. For example:

<Button Name="btnFirst" HorizontalAlignment="Center" VerticalAlignment="Center" Content="{Binding btnFirstContent, Source={StaticResource MyViewModel}}"/>

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Laxman
Top achievements
Rank 1
answered on 07 Sep 2012, 01:46 PM
Hi Support Team,

Thanks a lot.

Laxman.
Tags
General Discussions
Asked by
Laxman
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Laxman
Top achievements
Rank 1
Share this question
or