Hello, Hodaya,
Thank you for writing.
You can find below is a sample code snippet demonstrating how to delete a collection of rows from
RadGridView. Note that if you use a foreach loop for the RadGrid.Rows collection you can't modify the collection itself. That is why it is necessary to store the rows in a separate list and then delete the rows.
public
RadForm1()
{
InitializeComponent();
DataTable dt =
new
DataTable();
dt.Columns.Add(
"Id"
,
typeof
(
int
));
dt.Columns.Add(
"Name"
,
typeof
(
string
));
dt.Columns.Add(
"IsActive"
,
typeof
(
bool
));
for
(
int
i = 0; i < 10; i++)
{
dt.Rows.Add(i,
"Item"
+ i, i % 2 == 0);
}
this
.radGridView1.DataSource = dt;
this
.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
}
private
void
radButton1_Click(
object
sender, EventArgs e)
{
this
.radGridView1.BeginUpdate();
BindingList<GridViewDataRowInfo> rowsToDelete =
new
BindingList<GridViewDataRowInfo>();
foreach
(GridViewDataRowInfo row
in
this
.radGridView1.Rows)
{
if
(row.Cells[2].Value.ToString() ==
"False"
)
{
rowsToDelete.Add(row);
}
}
while
(rowsToDelete.Count > 0)
{
this
.radGridView1.Rows.Remove(rowsToDelete.First());
rowsToDelete.RemoveAt(0);
}
this
.radGridView1.EndUpdate();
}
The attached gif file illustrates the achieved behavior.
I hope this information helps. Should you have further questions I would be glad to help.
Regards,
Dess
Progress Telerik