CheckedListBox Question

D

Derek Martin

Here is some code that I need help with please:

Dim result As New ArrayList
Try
For i = 0 To objecttest1.PersonList.person_returnnumber - 1
result =
objecttest1.PersonList.time_returnpunches(objecttest1.PersonList.person_getb
yid(i).userid, "03/08/2004", "03/09/2004", True, False)
'The above line returns an object with several proerties, namely, a
punch id that I want to be able to get out of the checkedlistbox collection:
For j = 0 To result.Count - 1
If result(j).approval = True Then
CheckedListBox1.Items.Add(result(j).ToString, True)
Else
CheckedListBox1.Items.Add(result(j).ToString, False)
End If
Next
Next
....
End Try

Okay so far...now, I want to find out which object ID's in the
checkedlistbox collection have what state:

Dim item As Object
Dim quote As String = """"
For Each item In CheckedListBox1.Items
MessageBox.Show("Item with id: " + item.GetType.ToString + _ 'Problem
is on this line
" is: " +
CheckedListBox1.GetItemCheckState(CheckedListBox1.Items.IndexOf(item)).ToStr
ing() + ".")
Next

The segment item.GetType.ToString returns System.String which is confusing
me because I think it means that the objects in the checkedlistbox
collection are string objects and not the objects themselves, which would
explain why I can't reference a member of the punch object (id). Is this
correct?

If it is, how can I do this so that I get the object's time property for
each indexed collection? For example, I am wanting:

checkedlistbox1 index = 0 results in this messagebox: Item with ID: 932 is:
unchecked
where '932' is the ID property of the time object that was loaded into the
checkedlistbox

Thanks so much!

Derek
 
A

Armin Zingler

Derek Martin said:
Here is some code that I need help with please:

Dim result As New ArrayList
Try
For i = 0 To objecttest1.PersonList.person_returnnumber - 1
result =
objecttest1.PersonList.time_returnpunches(objecttest1.PersonList.person_getb
yid(i).userid, "03/08/2004", "03/09/2004", True, False)
'The above line returns an object with several proerties,
namely, a
punch id that I want to be able to get out of the checkedlistbox
collection:
For j = 0 To result.Count - 1
If result(j).approval = True Then
CheckedListBox1.Items.Add(result(j).ToString, True)
Else
CheckedListBox1.Items.Add(result(j).ToString, False)
End If
Next
Next
...
End Try

Okay so far...now, I want to find out which object ID's in the
checkedlistbox collection have what state:

Dim item As Object
Dim quote As String = """"
For Each item In CheckedListBox1.Items
MessageBox.Show("Item with id: " + item.GetType.ToString + _
'Problem
is on this line
" is: " +
CheckedListBox1.GetItemCheckState(CheckedListBox1.Items.IndexOf(item)).ToStr
ing() + ".")
Next

The segment item.GetType.ToString returns System.String which is
confusing me because I think it means that the objects in the
checkedlistbox collection are string objects and not the objects
themselves, which would explain why I can't reference a member of the
punch object (id). Is this correct?
Right

If it is, how can I do this so that I get the object's time property
for each indexed collection? For example, I am wanting:

checkedlistbox1 index = 0 results in this messagebox: Item with ID:
932 is: unchecked
where '932' is the ID property of the time object that was loaded
into the checkedlistbox

As you didn't add the objects to the listbox, only a string, there is no
relation to the original object.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
D

Derek Martin

Thanks for teh reply...Okay, so how can I add the object itself to the
checkedlistbox?

Thanks!
Derek
 
D

Derek Martin

Figured it out:
When adding it into the list, force the object itself to be added and
overload the tostring method in the object class.

:)
Thanks!
Derek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top