删除C#中的Datagriview行

时间:2016-03-15 08:55:21

标签: c# datagridview

我想从Datagridview中删除行。这是我的Datagridview

enter image description here

这是我用来删除行的代码

foreach (DataGridViewRow row in dataGridView.Rows)
{
    if (Convert.ToInt32(row.Cells["Column28"].Value) < 2 )
    {
        dataGridView.Rows.Remove(row);
    }
    else
    {
        if (Convert.ToInt32(row.Cells["Column29"].Value) < 6)
        {
            dataGridView.Rows.Remove(row);
        }
    }
}

但这是我得到的结果:

enter image description here

错误在哪里?

1 个答案:

答案 0 :(得分:1)

<?xml version="1.0" encoding="utf-8"?> <ListView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:layout_width="40dp" android:layout_height="40dp" android:padding="8dp" android:id="@+id/friends_image" /> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:layout_toRightOf="@+id/friends_image" android:gravity="center_vertical" android:id="@+id/list_item_friends_textview" /> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/text_view_id" /> 语句用于遍历集合以获取所需信息,但可以不能用于添加从源集合中删除项目以避免不可预测的副作用。

如果我们需要在源集合中添加或删除项目,请使用foreach循环。

for
相关问题