Highlighting Text in GridView column

3 posts, 0 answers
  1. Simon
    Simon avatar
    32 posts
    Member since:
    Apr 2007

    Posted 04 Jan 2011 Link to this post

    Hello

    I have a column in a RadGridView which I would like to apply HTML formatting to.
    If you look at the screen shot there is the Highlighted Text column and in it you
    will see the Html <STRONG> tags which need to bold the text which they are
    wrapping. How do I achieve this with the RadGridView. How can I via code apply
    an HtmlPlaceHolder so the Html tags are applied?

    Regards,
    Simon
  2. Simon
    Simon avatar
    32 posts
    Member since:
    Apr 2007

    Posted 04 Jan 2011 Link to this post

    Hello

    Please see the code below to set a column to see an RadHtmlPlaceholder.

    Regards,
    Simon

    public class GridViewHtmlPlaceHolderColumn : GridViewBoundColumnBase
       {
     
           public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)
           {
     
               // Initialize Class
               RadHtmlPlaceholder cellElement = new RadHtmlPlaceholder();
               // Set Binding
               cellElement.SetBinding(RadHtmlPlaceholder.HtmlSourceProperty, new Binding("Highlighted Text")
               {
                   Source = dataItem
               });
               // Return Element
               return cellElement;
     
           }
     
       }
  3. DevCraft banner
  4. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 05 Jan 2011 Link to this post

    Hello Simon,

     
    If you need to integrate RadHtmlPlaceHolder in a custom column you may use the following code:

    CustomColumn.cs:

    public class CustomColumn:GridViewDataColumn
        {
            public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)
            {
                var grid = cell.Content as Grid;
                if (grid == null)
                {
                   
                    grid = new Grid();
                    grid.Width = 150;
                    grid.Height = 150;
                    RadHtmlPlaceholder pl = new RadHtmlPlaceholder();
                    pl.SetBinding(RadHtmlPlaceholder.HtmlSourceProperty, new Binding("YourCustomProperty")
                    {
                        Source = dataItem
                    });
                    grid.Children.Add(pl);
                    cell.Content = grid;
                }
                return grid;
            }
             
            
        }

    MainPage.xaml:

    <UserControl x:Class="GridViewButton.MainPage"
         xmlns:local="clr-namespace:GridViewColumn"
     
        <Grid x:Name="LayoutRoot" Background="White" DataContext="{Binding Source={StaticResource SampleDataSource1}}">
            <telerik:RadGridView  AutoGenerateColumns="False" ItemsSource="{Binding Collection}">
                <telerik:RadGridView.Columns>
                    <local:CustomColumn Header="CustomColumn" IsReadOnly="True"/>
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>
     
        </Grid>
    </UserControl>

    In addition to this I would suggest you to use the following forum thread and the attached project for further reference.


    Please let me know how these works for you.


    All the best,
    Vanya Pavlova
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
Back to Top