|
-
March 11th, 2009, 09:51 AM
#11
Re: how to set the text property on a checkedlistbox collection
Just spent hours working this out myself, thought I'd join and post as fairly recent thread...
You shouldn't override the tostring method - you just need to use the DisplayMember property of checklistbox (N.B It does NOT come up in intellisense!).
For example create a class like this:
Private Class CheckedListItem
Private myId As Long
Private myTextToDisplay As String
Public Sub New(ByVal Id As Long, ByVal TextToDisplay As String)
myId = Id
myTextToDisplay = TextToDisplay
End Sub
Public ReadOnly Property Id()
Get
Return myId
End Get
End Property
Public ReadOnly Property TextToDisplay()
Get
Return myTextToDisplay
End Get
End Property
End Class
...Then make sure you set the 'DisplayMember' as shown in following....
Private Sub loadUsersList()
Dim oUser As User
Dim oListItem As CheckedListItem
myUsersCol.loadAllUsers()
' Does not show up in intellisense!...
Me.ckLstUsers.DisplayMember = "TextToDisplay"
Me.ckLstUsers.Items.Clear()
oListItem = New CheckedListItem(0, "<All Users>")
Me.ckLstUsers.Items.Add(oListItem, True)
For Each oUser In myUsersCol
oListItem = New CheckedListItem(oUser.Id, oUser.UserFullName)
Me.ckLstUsers.Items.Add(oListItem, True)
Next
End Sub
(For ref: The displaymember property is inherited from ListControl so will be use-able with un-checked listboxes as well).
Hope that helps!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|