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

Not able to find the Child Controls in rad Grid View

1 Answer 93 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 18 Dec 2012, 11:43 AM
Hi Support,
Please look at the below code, i was able to find the child controls in gird view with Trial version Dlls,
but now we have purchased the dlls and updated the reference and now unable to find the child controls in grid view.

Please look at the attached screenshot and you will see where i am getting issue.

FYI: We are using "RadControls for Silverlight Q3 2012"


<
UserControl x:Class="DemoDLL.MainPage"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"            
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" Loaded="UserControl_Loaded">
 
    <UserControl.Resources>
 
        <Style TargetType="telerik:GridViewHeaderCell" x:Key="HeaderStyleForAction">
            <Setter Property="Background">
                <Setter.Value>
                    <LinearGradientBrush  EndPoint="1.0,1.0" StartPoint="1.0,0">
                        <GradientStop Color="#626262" Offset="0.25" />
                        <GradientStop Color="#060606" Offset="1" />
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="telerik:GridViewHeaderCell">
                        <StackPanel HorizontalAlignment="Center" VerticalAlignment="Top" Orientation="Horizontal">
                            <TextBlock Text="ACTIONS" Foreground="White" Margin="0,5,5,0" FontFamily="Verdana"></TextBlock>
                            <Image Name="imgOptions" Tag="{Binding TableCompositeKey}" HorizontalAlignment="Center" VerticalAlignment="Top"
                                               Source="/TSN_SL;component/IMAGES/Options_Icon.png" Width="15" Height="15" Margin="0,5,0,0"  ToolTipService.ToolTip="Options"/>
                        </StackPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
 
        <Style x:Key="cellStyle" TargetType="telerik:GridViewCell">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="telerik:GridViewCell">
                        <Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                                <Image x:Name="imgEdit" Source="/TSN_SL;component/IMAGES/Pencil.png" ToolTipService.ToolTip="Edit" Stretch="None" Cursor="Hand"
                                       Margin="5,0,0,0"/>
                            </StackPanel>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
 
    </UserControl.Resources>
 
    <Grid x:Name="LayoutRoot" Background="White">
 
        <telerik:RadGridView x:Name="radGridView" Height="300" RowDetailsVisibilityMode="Collapsed"  SelectionMode="Multiple"
                                         FilteringMode="FilterRow" RowLoaded="radGridView_RowLoaded"
                                         CanUserResizeColumns="False" Margin="10,0,0,0" CanUserFreezeColumns="False" ColumnWidth="*" Width="Auto"
                                         ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Visible"
                                         IsReadOnly="True" ActionOnLostFocus="None" CanUserDeleteRows="True" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="4"
                                         AutoGenerateColumns="True" CanUserSelect="False"  AlternateRowBackground="LightGray" AlternationCount="2"
                                         GridLinesVisibility="None"  RowIndicatorVisibility="Collapsed"
                                         ShowGroupPanel="False">
 
            <telerik:RadGridView.Columns>
 
                <telerik:GridViewToggleRowDetailsColumn ExpandMode="Single">
 
                    <telerik:GridViewToggleRowDetailsColumn.ToggleButtonStyle >
 
                        <Style TargetType="telerik:GridViewToggleButton">
                            <Setter Property="PlusMinusTemplate">
                                <Setter.Value>
                                    <ControlTemplate x:Name="GridViewToggleButtonTemplate" TargetType="telerik:GridViewToggleButton">
                                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" x:Name="txtEmailsymbol">
                                             
                                            <TextBlock Text="@"  Name="txtSymbol" Padding="5,0,0,0" Foreground="Red"></TextBlock>
                                        </StackPanel>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
 
                    </telerik:GridViewToggleRowDetailsColumn.ToggleButtonStyle>
 
                </telerik:GridViewToggleRowDetailsColumn>
 
            </telerik:RadGridView.Columns>           
        </telerik:RadGridView>
 
    </Grid>
</UserControl>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls.GridView;
using Telerik.Windows.Data;
using System.Windows.Media.Imaging;
using Telerik.Windows.Controls;
 
namespace DemoDLL
{
    public partial class MainPage : UserControl
    {
        List<EmployeeEntity> personEntities = new List<EmployeeEntity>();
 
        public MainPage()
        {
            InitializeComponent();
 
            //Populate the person collection
            GetPersonData();
        }
 
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            //Bind to grid
            radGridView.ItemsSource = personEntities;
        }
 
        /// <summary>
        /// Populate the Person List
        /// </summary>
        private void GetPersonData()
        {
            for (int i = 1; i <= 10; i++)
            {
                personEntities.Add(new EmployeeEntity
                {
                    EmployeeId = i
                    ,
                    EmployeeName = string.Concat("Employee ", i)
                    ,
                    Age = 20 + i
                    ,
                    Salary = 5000 + i * 10
                    ,
                    DOJ = DateTime.Now.AddYears(-10).AddYears(i)
                    ,
                    IsInProject = i % 2 == 0 ? true : false
                });
            }
        }
 
        private void radGridView_RowLoaded(object sender, RowLoadedEventArgs e)
        {
            if (e.Row is GridViewRow)
            {
                var row = e.Row.DataContext;
                var cells = (e.Row as GridViewRow).ChildrenOfType<GridViewCell>();
 
                var abcd = (e.Row as GridViewRow).ChildrenOfType<TextBlock>();
 
                TextBlock txtSymbol = (e.Row as GridViewRow).ChildrenOfType<TextBlock>().Where(c => c.Name == "txtSymbol").FirstOrDefault();
 
                if (txtSymbol != null)
                {
                    txtSymbol.Foreground = new SolidColorBrush(Colors.Green);
                }
            }
        }
    }
}

1 Answer, 1 is accepted

Sort by
0
Accepted
Maya
Telerik team
answered on 18 Dec 2012, 11:49 AM
Hi Robert,

This is a know issue and has already been resolved. You can download our latest internal build, which contains the fix.
However, please keep in mind that working with visual elements like this is not recommended since RadGridView is virtualized control. This means that those elements will be recycled and reused on scrolling and the foreground you set might be applied to another TextBlock. You would better work with styles and style selectors (check out this article for a reference).   

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Robert
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or