如何从列表中删除项目? [英] How to delete an item from a list?

查看:125
本文介绍了如何从列表中删除项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个项目列表。每个项目都是一些字段的行和"删除"字段。按钮结束。点击"删除"按钮将从列表中删除此项目。

这是我的尝试。我为该项目创建了一个UserControl,其中包含一些文本块和一行"删除"按钮。按钮。然后我创建了一个ListBox并将UserControl的实例添加到它的Items集合中。一切顺利。但现在"删除"按钮单击事件在UserControl级别启动。我似乎无法在主屏幕中处理它,我需要从ListBox的项目集合中删除该项目。我这样做是错误的吗?

I need to create a list of items.  Each item is a row of some fields and a "Delete" button at the end.  Clicking "Delete" will remove this item from the list. 

Here's my attempt.  I created a UserControl for the item, which contains a row of a few textblocks and a "Delete" button.  Then I created a ListBox and add instances of the UserControl to it's Items collection.  All works well.  But now "Delete" button click event is fired up in the UserControl level.  I can't seem to get it handled in the main screen where I need to remove the item from the ListBox's items collection.  Am I doing it the wrong way? 

推荐答案

我之前所做的是在用户控件中创建一个在单击"删除"按钮时获得"提升"的事件。然后让主应用程序处理usercontrol事件。你需要更多细节吗?如果您可以发布您的解决方案文件,我可以修改代码,或者我可以从头创建一个,但目前没有很多时间。
What I've done before is create an event in the usercontrol that gets Raised when you click the Delete button.  Then have the main application handle the usercontrol event.  Do you need more specifics?  If you can post your solution files, I can modify the code, or I can create one from scratch but don't have a lot of time at the moment.


这篇关于如何从列表中删除项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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