Listbox properties

I want to keep track of different row properties in a Listbox.
I think the best way of storing these values is in a structure (‘Filename as string * 255, Size as Integer, IsFolder as Boolean, IsExpanded as Boolean, Indent as Integer’)
How can I attach a new instance of this structure to every new row?

Listbox.RowTag

Well, I’d rather use a custom class for storing those values. And as for storing the class instance, have a look at Listbox.RowTag…

Edit: Oh, Karen was first :slight_smile:

You both beat me to the punch.

[code]Dim s As SomeStruct

Listbox1.AddRow “Test row”
Listbox1.RowTag(Listbox1.LastIndex) = s[/code]

Ok… I know Rowtag. Let’s say I drop a folder with 300 files on a listbox.
Upon reading the folder’s contents I have different values for each instance of the structure. Sa far so good.

In Alwyn’s example: if I put this S in a loop it is used 300 times… Only the last row will keep it’s value as every new row overwrites the S values. Or is the S in row X separated form all the other instances of the SomeStruct?

I think that is why Alex suggested that you rather use a class than a structure, so that each row can store its own instance of information.

[quote=27738:@Alexander van der Linden]Ok… I know Rowtag. Let’s say I drop a folder with 300 files on a listbox.
Upon reading the folder’s contents I have different values for each instance of the structure. Sa far so good.

In Alwyn’s example: if I put this S in a loop it is used 300 times… Only the last row will keep it’s value as every new row overwrites the S values. Or is the S in row X separated form all the other instances of the SomeStruct?[/quote]

You would need to DIM the Structure in the loop to get new variables for each row…

But I would use class instead of a structure and use New

OK thanks. Trying…

Ok it works… storing the info that is… now for retrieving…

How do I retrieve a specific class property from a rowtag?

I stored in this way:

dim thisRowInfo as new Globals.RowInfo thisRowInfo.IsFolder = True thisRowInfo.IsExpanded = False thisRowInfo.FileName = textField1.text thisRowInfo.FileIcon = Document Listbox1.RowTag(Listbox1.lastIndex) = thisRowInfo

dim thisFilename as String = listbox1.rowtag(listbox1.listIndex).FileName doesn’t work.

dim thisFilename as String
Dim myClassInstance as MyClassName // Substitute the class you are using

// I always check to make sure the Rowtag is not nil and of the proper type first
if NOT ( listbox1.rowtag(listbox1.listIndex).objectValue is nil) Then
if ( listbox1.rowtag(listbox1.listIndex) ISA MyClassName) Then
myClassInstance = listbox1.rowtag(listbox1.listIndex)
thisFilename = myClassInstance.FileName
end if
end if

I see. So you have to re-read the info back in a new Classinstance? (if I understand it correctly)?

Not exactly, you’re still referencing the same instance, but you need to cast the rowtag as the class to access it’s members. I believe the following would work as well:

MyClassName(listbox1.rowtag(listbox1.listIndex)).FileName

I prefer to create a variable to reference it, especially if I need to access it more than once (getting/setting multiple properties or methods).

Works!. Many thanks!