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

Clear unbound grid

1 Answer 86 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dreyfus
Top achievements
Rank 1
Veteran
Dreyfus asked on 01 Jul 2020, 08:21 AM

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.

1 Answer, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 01 Jul 2020, 03:48 PM

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.
Tags
GridView
Asked by
Dreyfus
Top achievements
Rank 1
Veteran
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or