Clear unbound grid

2 posts, 0 answers
  1. Dreyfus
    Dreyfus avatar
    17 posts
    Member since:
    May 2019

    Posted 01 Jul Link to this post

    Is there a best way to clear contents of an unbound grid without removing the rows/columns?

    RadGridView.Rows.Clear() is not desirable because it deletes the actual rows.

  2. Nadya
    Admin
    Nadya avatar
    307 posts

    Posted 01 Jul Link to this post

    Hi, Jay,

    If I understand you correctly you would like to clear only the cell content in the data rows in an unbound grid without removing the existing rows and columns. To achieve this you can iterate through the cells of each row using the Cells collection of GridViewCellInfo. Thus, you can set GridViewCellInfo.Value property:

    foreach (GridViewRowInfo rowInfo in radGridView1.Rows)
    {
        foreach (GridViewCellInfo cellInfo in rowInfo.Cells)
        {
            if ((cellInfo.ColumnInfo.Name == "column1")
               || (cellInfo.ColumnInfo.Name == "column2")
               || (cellInfo.ColumnInfo.Name == "column3"))
            {
                cellInfo.Value = "";
            }
    
        }
    }

    I hope this helps. If you have other questions do not hesitate to contact me.

    Regards,
    Nadya
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top