Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

What membertype has a checkedlistbox

I want to add my own items to the checkedlistbox.
Normaly I inherits from the default item and add my changes but of what type is a checkedlistboxitem ?
By example for a listview is that listviewitem

Thanks.
0
dekeyzer
Asked:
dekeyzer
  • 3
  • 2
  • 2
2 Solutions
 
RonaldBiemansCommented:
It is of type object

        CheckedListBox1.Items.Add("whatever", True)
0
 
RonaldBiemansCommented:
The object  should have an inplementation of the tostring property though (which most have, although it will not always result in what you thought :-))


so you could even do something like this (although useless)

        Dim mi As Image
        mi = Image.FromFile("c:\myimage.bmp")

        CheckedListBox1.Items.Add(mi, True)
0
 
dekeyzerAuthor Commented:
Doesn't it have a specific type because i need to use some of the base class functions and with object you don't have that.

Sample for textbox :

Public Class DKWtxt
      Inherits Windows.Forms.TextBox
      Private mvarVerplicht As Boolean
      Public Sub New(ByVal Verplicht As Boolean)
            MyBase.New()
            pVerplicht = Verplicht
            If pVerplicht = True And MyBase.Text.Trim.Length = 0 Then
                  MyBase.BackColor = Color.Yellow
            Else
                  MyBase.BackColor = Color.White
            End If
      End Sub
      Public Property pVerplicht() As Boolean
            Get
                  Return mvarVerplicht
            End Get
            Set(ByVal Value As Boolean)
                  mvarVerplicht = Value
            End Set
      End Property
      Protected Overrides Sub OnTextChanged(ByVal e As EventArgs)
            MyBase.OnTextChanged(e)
            If pVerplicht = True Then
                  If Me.Text.Trim.Length = 0 Then
                        Me.BackColor = Color.Yellow
                  Else
                        Me.BackColor = Color.White
                  End If
            Else
                  Me.BackColor = Color.White
            End If
      End Sub
End Class
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
RonaldBiemansCommented:
No it doesn't , what base class functions do you want to change
0
 
S-TwilleyCommented:
When you pull the item back out of the checkedlistbox... you can cast it back to it's original type, and the original functionality of the object is exposed...  this is alot easier when you're only adding one type of object to the checked listbox, as you can be sure of what type you will be pulling back out
0
 
S-TwilleyCommented:
For example.. if you were adding the class Test (shown below), to a checkedlistbox... and at some point, wanted to examine all the checkeditems... but wanted access to the underlying items properties... you use a cast:

Class Test
    Public myFName As String = ""
    Public myLName As String = ""
    Public myAge As Integer = 0

    Public Overrides Function ToString() As String
         Return myFName  & " " & myLName
    End Function
End Class

================================

Then to add items to the CLB... simply

Dim tstItem As New Test
tstItem.myFName = "Steven"
tstItem.myLName = "Twilley"
tstItem.myAge = 23

CheckedListBox1.Items.Add(tstItem)

===============================

Then later, when you want to look at the underlying checked items...

        Dim thisItem As Test

        For Each thisItem In CheckedListBox1.CheckedItems
            MsgBox(thisItem.myAge.ToString)
        Next

(This assumes you were only adding Test Class items to your checkedlistbox)

If you're adding a mixture of classes/ types of objects to your checked list box... then you can use the following

        Dim thisItem As Object

        For Each thisItem In CheckedListBox1.CheckedItems
            If TypeOf thisItem Is Test Then
                Dim thisItem_Test As Test = DirectCast(thisItem, Test)
                MsgBox(thisItem_Test.myAge)
            ElseIf TypeOf thisItem Is String Then
                MsgBox("String: " & thisItem)
            End If
        Next
0
 
dekeyzerAuthor Commented:
Thank you S-Twilley,
I see now that i possibly don't have to change base class functions, I can always access my own functions after the base event has fired.

Luc.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now