How to add object inside grid cell

4 posts, 0 answers
  1. Nicole
    Nicole avatar
    30 posts
    Member since:
    Mar 2011

    Posted 17 Jan 2012 Link to this post

    I am attempting to insert a polygon inside a RadGrid cell in code behind; the actual polygon that is inserted will depend on some conditions not yet reflected in the code below.  I've built a sample polygon, but I can't find the method to add it to the cell.  Can anyone tell me what I need to do here?  This has to happen in the code behind; I can't do it in the XAML.

    void gvAGSE_RowLoaded(object sender, RowLoadedEventArgs e)
    {
        if (e.Row is GridViewRow && !(e.Row is GridViewNewRow))
        {
            foreach (GridViewCell cell in e.Row.Cells)
            {
                if (cell.Column.Header.ToString().Contains("%"))
                {
                    double cellValue = (double)cell.Value;
                    if (cellValue >= 0)
                    {
                        cell.Background = GetFMCBackgroundColorCode(cellValue);
                        cell.Foreground = GetFMCForegroundColorCode(cellValue);
                        Polygon poly = downArrow(GetFMCForegroundColorCode(cellValue));
                        //cell.Child.Insert(poly);
                    }
                    else
                    {
                        cell.Content = "N/A";
                    }
                }
            }
        }
    }
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 17 Jan 2012 Link to this post

    Hello,

     Generally the proper way to style conditionally the grid cells or load different elements in the grid cells is with style and template selectors. 

    Regards,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. Nicole
    Nicole avatar
    30 posts
    Member since:
    Mar 2011

    Posted 17 Jan 2012 Link to this post

    Would that entail setting the Style in the column definition like so:

     

    ColPercent.CellStyle = this.LayoutRoot.Resources["DownArrowStyle"] as Style

    Or can I set it at the cell level, with something like (pseudocode):

    cell.Style = new Telerik.Windows.Controls.ConditionalStyleSelector());

    Or, do you have an example using C#? 
  4. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 17 Jan 2012 Link to this post

    Hello,

     You can find both declarative and C# examples in your local copy of our demos. 

    All the best,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top