Update cell's text in RadGridView

7 posts, 1 answers
  1. flanky
    flanky avatar
    4 posts
    Member since:
    Jul 2010

    Posted 14 Jul 2010 Link to this post

    I bind an entity to the RadGridView,then I update some cell's text  of gridview.
    code like below:

    radGridView.Rows[0].Cells[0].CellElement.Text = "Male";

    But when gridview is refreshed(such as when I scroll the scrollbar of the gridview.), the cell's text I just set is gone instead of the value of the entity used to bind to the grdiview.
    So how can I make cell's text keep unchanged ?

    Thanks in advance,
  2. Svett
    Admin
    Svett avatar
    728 posts

    Posted 20 Jul 2010 Link to this post

    Hello flanky,

    This behavior is due to virtualization capabilities of the grid. You can read more about that in this documentation article. CellElement property of GridViewCellInfo class can be null if the cell is not visible in the currently presented area of the grid. If you want to change the text of concrete CellElement you should use CellFormatting event. You may refer to this help article.

    Kind regards,
    Svett
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Answer
    Deiver
    Deiver avatar
    1 posts
    Member since:
    Jul 2012

    Posted 09 Jul 2012 Link to this post

    I Had the same problem, but this code worked for me:

    row.InvalidateRow();
  5. Raminmjj
    Raminmjj avatar
    6 posts
    Member since:
    Apr 2007

    Posted 26 Apr Link to this post

    Hi.

    in below sample I need set Text property.

    but "CellElement.Text" does not exist.

    how can I do that?

    foreach (GridViewRowInfo rowInfo in radGridView1.MasterTemplate.Rows)
    {
        foreach (GridViewCellInfo cellInfo in rowInfo.Cells)
        {
            if (cellInfo.ColumnInfo.HeaderText == "Name")
            {
              cellInfo.CellElement.Text = "TestName";
            }
        }
    }

  6. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 27 Apr Link to this post

    Hello Ramin,

    Thank you for writing.

    It is suitable to use the CellFormatting event in order to customize the text. Additional information is available here: http://docs.telerik.com/devtools/winforms/gridview/cells/formatting-cells

    I hope this information helps. Should you have further questions I would be glad to help.

     Regards,
    Dess
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  7. Raminmjj
    Raminmjj avatar
    6 posts
    Member since:
    Apr 2007

    Posted 07 May in reply to Dess Link to this post

    Hello Dess,
    Thank you for your answer.
    But, "CellFormatting event" is not a good solution. some times we want to analyze a row in methods or functions, like a report generator.
    please add Text property to CellInfo.

    thank you.
  8. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 10 May Link to this post

    Hello Ramin,

    Thank you for writing back. 

    GridViewCellInfo represents the data cell which stores the relevant information. However, the GridCellElement represents the visual cell. RadGridView uses virtualization and cell elements are created only for currently visible cells and are being reused during operations like scrolling, filtering, grouping and so on. The CellFormatting event is explicitly introduced to handle customizing the visual cell elements and change their text.

    Would it be possible to give us some more details about the specific case and why the CellFormatting event is not applicable to your case? Thus, we would be able to think about an alternative solution and assist you further.

    I am looking forward to your reply.

    Regards,
    Dess
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for WinForms is Visual Studio 2017 Ready