DataGridView.Rows.RemoveAt(INT指数)不会在Windows表单中删除行? [英] DataGridView.Rows.RemoveAt(int index) doesn't remove row in windows form?

查看:873
本文介绍了DataGridView.Rows.RemoveAt(INT指数)不会在Windows表单中删除行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int i = dataGridView1.CurrentRow.Index;
dataGridView1.Rows.RemoveAt(i);

以上code删除当前选中的行(只允许选择1行),但我仍然可以看到该行仍保留在datagridview的。我错过的更新或废止?

The above code for deleting current selected row (only allow to select 1 row) but I still can see the row remains in datagridview. Did I miss an update or invalidate ?

PS:dataGridView1的是数据绑定

ps: dataGridView1 is data-bound.

PS2:我使用LINQ查询绑定数据,我不想再查询只显示一列被删除,我认为这会降低性能

ps2: I use linq query to bind data and I don't want to query again for just to show a row was deleted, I think it will slow down performance.

推荐答案

从数据源中删除的项目,然后再次绑定。

remove the item from the datasource, and bind again.

由于数据来自LINQ,结合之前,你可以这样做:

since the data comes from linq, before binding, you can do:

var result = fooLinq.ToList();
dataGridView1.DataSource = result;


//to remove and bind again
var result = dataGridView1.DataSource as List<FooType>;
result.RemoveAt(fooIndex);
dataGridView1.DataSource = result;

这篇关于DataGridView.Rows.RemoveAt(INT指数)不会在Windows表单中删除行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆