vb.net - 删除 CheckedListBox 中的选定条目
问题描述
再会!所以从 CheckedListBox 中删除所有勾选的条目
For Each item In CheckedListBox1.CheckedItems.OfType(Of String)().ToList()
CheckedListBox1.Items.Remove(item)
Next item
告诉我如何删除 CheckedListBox 中选定的条目?
在图片中,名称为 3 的记录被突出显示。是否有可能以及如何在不检查的情况下删除它?
解决方案
这是一个简单的例子
- 删除所有选中的项目
- 删除当前项目而不考虑选中状态。
表格代码
Imports System.Globalization
Public Class Form1
Private Sub RemoveCheckedButton_Click(sender As Object, e As EventArgs) Handles RemoveCheckedButton.Click
If MonthCheckedListBox.CheckedItems.Count > 0 Then
MonthCheckedListBox.CheckedItems.Cast(Of String)().ToList().
ForEach(Sub(item) MonthCheckedListBox.Items.Remove(item))
SetActive()
End If
End Sub
Private Sub RemoveCurrentButton_Click(sender As Object, e As EventArgs) Handles RemoveCurrentButton.Click
If MonthCheckedListBox.Items.Count > 0 Then
MonthCheckedListBox.Items.RemoveAt(MonthCheckedListBox.SelectedIndex)
SetActive()
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
MonthCheckedListBox.Items.AddRange(
Enumerable.Range(1, 12).
Select(Function(index)
Return DateTimeFormatInfo.CurrentInfo.GetMonthName(index)
End Function).ToArray())
SetActive()
End Sub
Private Sub SetActive()
ActiveControl = MonthCheckedListBox
If MonthCheckedListBox.Items.Count > 0 Then
MonthCheckedListBox.SelectedIndex = 0
End If
End Sub
End Class
推荐阅读
- python - 在创建动态网址时,我得到一个带有参数错误的“dashboard_group”的反向
- openshift - 为什么在openshift中rest api没有从3.x升级到4.x?
- c# - 检查所有表中同一列的值[实体框架]
- ios - 集合视图单元格快速滚动到中心时出现问题
- java - 根据输入的大小保留数组元素
- typescript - TypeScript 自动 `as const` 我的类型导致错误
- php - WooCommerce 用户注册 - 对没有状态的国家禁用状态验证
- google-kubernetes-engine - 具有自动缩放功能的 Helm stable/nginx-ingress,HPA 无法读取 CPU 或内存指标
- c - 如何让 C 中的 strtol() 函数将字符串解释为二进制补码?
- swift - 在 didReceive 响应中执行 Segue:UNNotificationResponse