|
-
May 1st, 2009, 01:18 PM
#1
Thread Starter
New Member
Help populating array with checklistbox
I made a quick search but couldn't find any help
I need to put the values of a checklist box into an array. I've found several solutions on the internet but all of these don't seem to work for integer arrays. This is what I've got so far
" Dim RemoveValues(checklistRemoveBrew.CheckedItems.Count - 1) As Integer
Dim C As Integer
For C = 0 To checklistRemoveBrew.CheckedItems.Count - 1
RemoveValues(C) = checklistRemoveBrew.CheckedItems(C)
Next "
Thanks!
-
May 1st, 2009, 01:48 PM
#2
Re: Help populating array with checklistbox
Just to clarify - are you only wanting to put the checked items into the array as that is what your current code would do, but not what your question says.
The problem I can see is you are trying to stuff an object into an integer - the checkeditemscollection doesn't contain integers, but objects so you need to cast the item to an integer. You can use the cint() function, integer.tryparse method or a number of other methods to do that.
-
May 1st, 2009, 02:25 PM
#3
Thread Starter
New Member
Re: Help populating array with checklistbox
 Originally Posted by keystone_paul
Just to clarify - are you only wanting to put the checked items into the array as that is what your current code would do, but not what your question says.
The problem I can see is you are trying to stuff an object into an integer - the checkeditemscollection doesn't contain integers, but objects so you need to cast the item to an integer. You can use the cint() function, integer.tryparse method or a number of other methods to do that.
How do i use the cint() function?
Thanks
-
May 1st, 2009, 02:49 PM
#4
Re: Help populating array with checklistbox
RemoveValues(C) = cint(checklistRemoveBrew.CheckedItems(C))
You should note though that this will raise an exception if it can't be converted to an integer.
-
May 1st, 2009, 03:02 PM
#5
Re: Help populating array with checklistbox
Try this one line of code:
Code:
Dim RemoveValues() As Integer = Array.ConvertAll(Of Object, Integer)(checklistRemoveBrew.CheckedItems.Cast(Of String)().ToArray, AddressOf Convert.ToInt32)
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
|