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

CellFormatting

2 Answers 253 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jacques
Top achievements
Rank 1
Jacques asked on 01 Aug 2011, 02:42 PM
Hello,
I'm
formatting some columns RadGridView to give effect link in a cell.
I'm doing this using the event "CellFormatting." The effect works well until you use the scroll bar to navigate between records. We realize that some cells that are not in the context of link is getting the effect. It seems to me that there is a problem to apply the effect on the grid at the time the scrolling and done quickly.

Tks.

 Below is the code inserted to modify the cell.
public void CtrlDataGridList_CellFormatting(object sender, CellFormattingEventArgs e)
        {
            switch (e.Column.Name)
            {
                case "CommandColumnSearchMother":
                case "CommandColumnSearchFather":
                    if (!string.IsNullOrWhiteSpace(e.CellElement.Text.Trim()))
                    {
                        e.CellElement.CustumizeLinkCell();
                    }
                    break;
                case "CommandColumnOpen":
                    if (string.IsNullOrEmpty(_openMessage))
                    {
                        _openMessage = I18n.Term.I18nTerm.GetMessage("OPEN");
                    }
                    e.CellElement.Text = _openMessage;
                    e.CellElement.CustumizeLinkCell();
                    break;
            }
        }
 
public static void CustumizeLinkCell(this GridCellElement cellElement)
        {
            cellElement.Font = new Font(SystemFonts.DialogFont, FontStyle.Underline);
            cellElement.ForeColor = Color.Blue;
        }

 

2 Answers, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 04 Aug 2011, 10:10 AM
Hi Jacques,

Thank you for writing.

You have done one part of the formatting. Because of the virtualization our RadGridView utilizes, the visual style of the cells is reused, this is why there are cells that are formatted without reason. What you have to do is take care of the cases where the style should not be applied and reset the properties. Please consider the following code snippet which demonstrates this:
public void CtrlDataGridList_CellFormatting(object sender, CellFormattingEventArgs e)
{
  switch (e.Column.Name)
  {
    case "CommandColumnSearchMother":
    case "CommandColumnSearchFather":
      if (!string.IsNullOrWhiteSpace(e.CellElement.Text.Trim()))
      {
        e.CellElement.CustumizeLinkCell();
      }
      else
      {
        e.CellElement.RestoreLinkCell();
      }
      break;
      case "CommandColumnOpen":
        if (string.IsNullOrEmpty(_openMessage))
        {
          _openMessage = I18n.Term.I18nTerm.GetMessage("OPEN");
        }
        e.CellElement.Text = _openMessage;
        e.CellElement.CustumizeLinkCell();
        break;
  }
}
  
public static void CustumizeLinkCell(this GridCellElement cellElement)
{
  cellElement.Font = new Font(SystemFonts.DialogFont, FontStyle.Underline);
  cellElement.ForeColor = Color.Blue;
}
  
public static void RestoreLinkCell(this GridCellElement cellElement)
{
  cellElement.ResetValue(LightVisualElement.FontProperty, ValueResetFlags.Local);
  cellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
}

I hope this will be usefull for you. If you have further questions, I would be happy to help.

All the best,
Ivan Petrov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
0
Jacques
Top achievements
Rank 1
answered on 04 Aug 2011, 02:09 PM
It worked very well !
Thank you.
Tags
GridView
Asked by
Jacques
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Jacques
Top achievements
Rank 1
Share this question
or