• Welcome to Valhalla Legends Archive.
 

ListItem and ListSubItem objects

Started by LivedKrad, June 17, 2005, 01:22 PM

Previous topic - Next topic

LivedKrad

At the moment, I have code down where I am assigning a value to a ListItem object that I recently added to the listview.


Dim curItem As ListItem
Set curItem = Form1.ListView1.ListItems.Add(, , product)


I did the same process to set a ListSubItem object to curItem's subitem.

Dim cursubItem As ListSubItem
Set cursubItem = Form1.ListView1.FindItem(curItem.Text, , curIndex).ListSubItems.Add(, , Username)


The purpose of this was to provide access to previously unexposed properties of a ListView's SubItem item, and to make accessing to the already exposed ones a little easier. Now comes the problem..

I've tried and tried to set the cursubItem value  to point to an item's SubItem already in the ListView. I either am doing something wrong or I suck at life. I guess I'm going about it the wrong way, can anyone offer insight as to how to assign an item's SubItem already in the ListView to a ListSubItem object?

LivedKrad

The fact that I gained no reply (yes I'm impatient) prompted me to solve the problem on my own. With a little help from MSDN, I accomplished my task. For future references to this problem or another instance of this problem down the road, I wrote a small amount of code to demonstrate how objects reduce lengthy code.


Dim ptrList As listview
Dim curItem As ListItem
Dim ptrItem As ListItems
Dim ptrSubItem As ListSubItems
Dim curSubItem As ListSubItem
-----------------------------------------------------------------------------------
Private Sub Command1_Click()
ptrItem.Add , "Hello", "Hello World"

   Set curItem = ptrItem.Item("Hello")
   Set ptrSubItem = ptrList.ListItems(curItem.Index).ListSubItems

ptrSubItem.Add , "World", "Goodbye World"

   Set curSubItem = ptrSubItem.Item("World")

curSubItem.ForeColor = vbBlue 'We can now reference all properties of any item (specified by any unique key exemplified above)
curItem.Bold = True 'We can now reference all properties of any SUB item (specified by any unique key exemplified above)
End Sub
--------------------------------------------------------------------------------------------
Private Sub Form_Load()
Set ptrList = lv1
Set ptrItem = ptrList.ListItems
End Sub


LivedKrad

#3
At the moment it was urgent for reasons that do not concern you, assuming that was even your business.

Edit: For additional reponses to your questions, see the statement inside the parentheses of post #2. Also, I removed the "bump" post so as to make you look like a fool when this post gets read at position-in-forum five or so and there is no "bump" in question! Owned! (</kidding>)

NicoQwertyu

#4
Quote from: LivedKrad on June 18, 2005, 12:22 AM
At the moment it was urgent for reasons that do not concern you, assuming that was even your business.

Edit: For additional reponses to your questions, see the statement inside the parentheses of post #2. Also, I removed the "bump" post so as to make you look like a fool when this post gets read at position-in-forum five or so and there is no "bump" in question! Owned! (</kidding>)
In that case, any of your future posts that I may be able to help you with "don't concern me," asshole.

LivedKrad

#5
Not sure how I'm an asshole just because I said that the reason I bumped it was not of your concern. Care to elaborate, friend?

Edit: Although I am deeply saddened and dismayed by the fact that I shall never receive your help, I forsee *most* of my future questions being answered by someone who is equally as godly as you in the language of Visual Basic.

QwertyMonster

Off topic: You two are argueing over nothing. Its pretty much pointless.

Locking this topic or stopping might help.

On Topic: Nice job on solving it on your own and posting how you did it. Congrats.

LivedKrad

May help someone else in the future, so why not! As many bot sources as I've seen, people don't utilize objects properly, if at all. People seem more concerned about the non-objected oriented side of VB, the rapid development event-driven side. The reason I'm trying to get more objecto oriented is because I want to get to know the collections and types and objects a lot better; this way I can utilize VB to its full potential and even mimic some of the main OOPL aspects like encapsulation and inheritance.

VB has a lot more to offer than what most BNCS bot writers see. :(