【问题标题】:Disable an item in CheckListBox in VB.NET?在 VB.NET 中禁用 CheckedListBox 中的项目?
【发布时间】:2018-09-26 03:22:56
【问题描述】:

我这里有代码,但它只填充清单框中的项目。

Dim lst As New List(Of String) From {dtr.GetInt32("fps_pump_id")}

Do
    For Each items As String In lst
       y = dtr.GetInt32("fps_pump_id") 
       PumpStation.CheckedListBox1.Items.Add(y & " [" & items & "]")
       PumpStation.CheckedListBox1.Items(y).Enabled = False 'this line won't work
    Next
    x += 1
Loop Until x = ps_table.Rows.Count

dtr.getIn32("fps_pump_id") 是一个预加载的MySqlDataReader,用于从本地数据库中获取数据。

【问题讨论】:

标签: vb.net winforms checkedlistbox


【解决方案1】:

您可以在复选框中添加项目:

CheckedListBox1.Items.Add(New ListItem With {.Text = y & " [" & items & "]", .Value = y, .Enabled = False})

【讨论】:

  • ListItem 有什么用?
  • ListItem 表示列表/行中的 ITEM。这里 ListItem 包含 4 个对象: 1. 文本:在屏幕上显示为复选框标签 2. 值:复选框项的值 3. 启用:真/假。默认为真 4。选择:真/假。默认为假
  • 我认为您所说的 ListItem 来自 ASP.NET 或 C#,因为 Add() 上的参数仅包含(文本,布尔值)。在这种情况下,如果 CheckListBox 上新添加的项目将被加载为 Checked 或 Unchecked,则布尔值用作“标志”
  • @kendev :就您可以使用的控件/对象而言,C# 与 VB.NET 相同,但是对于 ASP.NET 的答案建议是正确的。我已编辑您的问题以包含 winforms 标记(Windows 窗体,或简称为 WinForms),我想这是您正在使用的技术。它应该有助于避免一些混乱/不确定性。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-09-05
  • 1970-01-01
  • 1970-01-01
  • 2014-09-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多