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

How to add object inside grid cell

3 Answers 73 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Nicole
Top achievements
Rank 1
Nicole asked on 17 Jan 2012, 03:32 PM
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";
                }
            }
        }
    }
}

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 17 Jan 2012, 03:37 PM
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 >>

0
Nicole
Top achievements
Rank 1
answered on 17 Jan 2012, 03:51 PM
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#? 
0
Vlad
Telerik team
answered on 17 Jan 2012, 03:53 PM
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 >>

Tags
GridView
Asked by
Nicole
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Nicole
Top achievements
Rank 1
Share this question
or