0

I have code here but it only populates items in checklistbox.

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") is a pre-loaded MySqlDataReader that I used to fetch data from my local database.

Dale K
  • 25,246
  • 15
  • 42
  • 71
kendev
  • 27
  • 5

1 Answers1

0

You can add items in checkbox as:

CheckedListBox1.Items.Add(New ListItem With {.Text = y & " [" & items & "]", .Value = y, .Enabled = False})
Dale K
  • 25,246
  • 15
  • 42
  • 71
Anu
  • 326
  • 1
  • 13
  • What's the ListItem for? – kendev Sep 26 '18 at 05:34
  • ListItem represents ITEM in List/row. Here ListItem contains 4 objects: 1. Text : displays on screen as checkbox label 2. Value : value of checkboxitem 3. Enabled : true/false. Default is true 4. Selected: true/false. Default is false – Anu Sep 26 '18 at 06:04
  • I think that `ListItem` that you're talking about is from ASP.NET or perhaps C#, coz the parameters on Add() consists only of (text, boolean). In this case, the boolean serves as a "flag" if the newly added item on CheckListBox will be loaded as Checked or Unchecked – kendev Sep 26 '18 at 06:20
  • @kendev : C# is equal to VB.NET in the sense of what controls/objects you can use, however you are correct about that what the answer suggests is for ASP.NET. I have edited your question to include the `winforms` tag (_Windows Forms_, or _WinForms_ for short), which I suppose is the technology you're using. It should help avoid some confusion/uncertainty. :) – Visual Vincent Sep 26 '18 at 14:45