- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在使用 Compact Framework 开发一个智能设备项目。
我有一个 ListView
,其中包含多个可检查的 ListViewItem
:属性 CheckBoxes
为真。我一次只需要检查一个 ListViewItem
,所以我订阅了 ItemCheck
事件:
// I need to know the last item checked
private ListViewItem lastItemChecked;
private void listView_ItemCheck(object sender, ItemCheckEventArgs e)
{
if (lastItemChecked != null && lastItemChecked.Checked)
{
/* I need to do the following to prevent infinite recursion:
i.e. subscribe and then unsubscribe the ItemCheck event. */
listView.ItemCheck -= listView_ItemCheck;
lastItemChecked.Checked = false;
listView.ItemCheck += listView_ItemCheck;
}
lastItemChecked = listView.Items[e.Index];
}
是否有更好的方法来防止无限递归和 Stack Overflow
?
最佳答案
好吧,我认为可能比处理 EventHandler 更好的是检查 lastItemCheck 是否是来自 EventArgs 的当前项目。像这样:
// I need to know the last item checked
private ListViewItem lastItemChecked;
private void listView_ItemCheck(object sender, ItemCheckEventArgs e)
{
// if we have the lastItem set as checked, and it is different
// item than the one that fired the event, uncheck it
if (lastItemChecked != null && lastItemChecked.Checked
&& lastItemChecked != listView.Items[e.Index] )
{
// uncheck the last item and store the new one
lastItemChecked.Checked = false;
}
// store current item
lastItemChecked = listView.Items[e.Index];
}
我想你会同意,重新分配 EventHandlers 比简单地检查存储对象的引用要糟糕一些。
关于c# - 一次只检查一个 ListViewItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13858565/
我有一个 ListView ,其中包含几个动态创建的项目,每个项目都有两个子项目,它们是数量和代码,在查询数据库后应更新数量,但为了使代码更具可读性,我想通过访问子项目键而不是它的索引,比如: 子项目
我的 ListViewItems 中有删除按钮。从这些按钮的点击事件中,我想在通过数据库中的 ID 删除项目之前显示一个确认对话框。 ID 存储在项目的 ViewHolder 中。 如何从 Alert
我有一个 ListView,其中 ListView 项目有按钮和文本 block .... 塞纳里奥: 我可以在不选择 ListView 项目的情况下单击按钮,即选择最后一个项目,然后如果我尝试单击第
寻求帮助。 是否有机会通过ViewModel {Binding}更改Listviewitem的ContentBorder:BorderBrush? Something like this 最佳答案 更
我需要覆盖 ListViewItem 的预定义样式以使选择不可见。如果我将整个样式复制到我的资源中并进行编辑,我知道该怎么做。但我不敢相信没有比复制整个样式更轻松的方法了。所以我发现默认的 ListV
下面是一些构建 ListView 的代码示例。这是我第一次尝试更改 ListView 中项目的颜色和字体。下面的代码可以毫无问题地填充 ListView,但它不使用字体。有人可以告诉我我在这里做错了什
我正在开发一个通用 Windows 应用程序,其中有一个带有 DataTemplate 的 ListView。我想让 ListView 可扩展,当我单击(选择)一个项目时,所选项目的高度会随着动画而增
我有一些来自集合的 ListViewItem,我创建了一个 DataTemplate,这样每个 ListViewItem 都有一个 Button 作为子控件:
对于哪些操作,我应该使用 Checkbox 与 ListViewItem 的 SelectedItem?我不禁认为这只是个人喜好,但话又说回来,我仍然不知道。 最佳答案 如果您选择其他项目,已选中的项
我正在使用 C# 创建 Windows 窗体应用程序。该窗体包含一个 ListView。这是红十字会调度员的应用程序。 ListView 有一个所有单元的列表。每个单元都有一个状态。此状态需要更改。因
有一段时间我被这个小问题难住了。 W10 下的 ListView 有一些我无法理解的奇怪行为。考虑一个简单的列表:
我有一个按钮作为每个 ListViewItem 的最后一列。按下按钮时,我需要在单击事件中找到按钮(发件人)父 ListView 项。 我试过: ListViewItem itemToCancel =
在我当前使用 Javascript 中的 gridlayout 实现的 listview 中,如果我右键单击某个项目,则会显示一个显示“复制”的上下文菜单。我想覆盖此上下文菜单事件以选择元素而不是显示
当我向用户显示我的自定义 listviewitem 时,每个项目中包含的所有项目和对象都具有我想要的颜色, 但是当滚动和选择(使用 onListItemClick )时,项目不会更改所需颜色的背景颜色
关于构造的快速简单的问题。 我有以下用于将项目添加到 ListView 的代码。 ListViewItem item = new ListViewItem(); item.Text = file; i
我有一个包含三列的 ListView,我想为每一列添加字符串 这是代码 ListViewItem tempLV = new ListViewItem("first"); tempLV.SubItems
我正在尝试在自定义 ListView 中实现搜索功能因此我隐藏了Items自定义 ObservableCollection这允许 AddRange ,类似于 one defined on damonp
我正在使用 Compact Framework 开发一个智能设备项目。 我有一个 ListView,其中包含多个可检查的 ListViewItem:属性 CheckBoxes 为真。我一次只需要检查一
我有一个 ListView (WinForms),我想通过单击按钮在其中上下移动项目。要移动的项目是已检查的项目。因此,如果选择项目 2、6 和 9,当我按下向上移动按钮时,它们将变为 1、5 和 8
我有一个 ListView,对于 View = List,我想让列表项填满控件的整个宽度。也就是说,当您单击一个项目时,整行都会突出显示。 我在 ListView 或 ListViewItem 中找不
我是一名优秀的程序员,十分优秀!