Cells' values

2 posts, 1 answers
  1. Frank
    Frank avatar
    13 posts
    Member since:
    May 2006

    Posted 25 Mar 2009 Link to this post

    Hi everybody.
    I have a question. In the code below I'm trying replace cells with a specific value with an empty string, but this step changes also the values in the database table for corresponding cells.
    GridViewRowCollection rowCollection = someGridView.Rows;
    foreach (GridViewRowInfo info in rowCollection)
        if (info.Cells["someColumn"].Value.ToString() == "someValue")
             info.Cells["someColumn"].Value = "";

    How can I avoid such a behavior, without  creating another foreach loop in order to restore previous values?
    Thanks in advance.
  2. Answer
    Jack avatar
    2335 posts

    Posted 25 Mar 2009 Link to this post

    Hello Frank Effenberger,

    You should process the CellFormatting event if you want to change only the text displayed on the screen. You should change the Text property of the desired cells. Here is a sample:

    void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e) 
        GridDataCellElement cell = e.CellElement as GridDataCellElement; 
        if (cell != null && cell.ColumnIndex == 2 && (int)cell.Value > 5) 
            cell.Text = ""

    I hope this helps. If you need further assistance, I will be glad to help.

    Kind regards,
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  3. DevCraft R3 2016 release webinar banner
Back to Top