WPF DataGrid中删除SelectedItems [英] WPF DataGrid Remove SelectedItems

查看:354
本文介绍了WPF DataGrid中删除SelectedItems的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我一直工作在其中进口数据programmicaly到WPF DataGrid中的一个项目。



我几乎与项目,但我离开的东西做!出去是一个按钮来删除选定的细胞,这就是我卡住了。



我用我的DataGrid中的基本知识,写了这个代码:

  VAR电网= DataGrid1中; 
如果(grid.SelectedIndex> = 0)
{
的for(int i = 0; I< = grid.SelectedItems.Count;我++)
{
grid.Items.Remove(grid.SelectedItems [I]);
};
}



做工精细于消除唯一入选就像CURRENTITEM的项目,但它不删除了超过2选定的项目!



数据网格我至少应该至少包含100个项目。我添加了一个全部删除选项,但这也是必要的。



如果有人给我解决,我会心存感激。


< DIV CLASS =h2_lin>解决方案

通过删除选定的项目要更改 SelectedItems 集合。你应该先复制它,然后开始删除。


Recently I've been working on a project which imports data programmicaly into a WPF DataGrid.

I'm almost done with the project but the thing that I left out was a button to remove selected cells and this is where I'm stuck!

I wrote this code using my basic knowledge of DataGrids:

var grid = dataGrid1;
if (grid.SelectedIndex >= 0)
 {
   for (int i = 0; i <= grid.SelectedItems.Count; i++)
   {
      grid.Items.Remove(grid.SelectedItems[i]);
   };
 }

Works fine on removing only the item selected just like CurrentItem but it doesn't remove anymore than 2 selected items!

The DataGrid I have should at least contain a minimum of 100 items. I've added a remove all option but this is also necessary.

I'll be thankful if anyone gives me the solution.

解决方案

By removing selected item you are changing SelectedItems collection. You should copy it first and then start removing.

这篇关于WPF DataGrid中删除SelectedItems的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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