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

Highlighting Text in GridView column

2 Answers 82 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 04 Jan 2011, 09:20 AM
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 Answers, 1 is accepted

Sort by
0
Simon
Top achievements
Rank 1
answered on 04 Jan 2011, 04:55 PM
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;
 
       }
 
   }
0
Vanya Pavlova
Telerik team
answered on 05 Jan 2011, 04:54 PM
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
Tags
GridView
Asked by
Simon
Top achievements
Rank 1
Answers by
Simon
Top achievements
Rank 1
Vanya Pavlova
Telerik team
Share this question
or