Nested TLists question

BlitzMax Forums/BlitzMax Programming/Nested TLists question

Nennig(Posted 2015) [#1]
Hi,

I need to store a TList within a TList and came up with the following code.
However how do I print the content of a specific element of the row TList?

For example, I might be interested of printing the content of the 2nd element of row.
How would I do that?

Many thanks for your help.

	Local col:TList = New TList
	Local row:TList = New TList
	
	col.addlast("hello")
	col.addlast("world")
	col.addlast ("this")
	col.addlast("is")
	col.addlast ("awesome")
	
	
	row.addlast(col)
	row.addlast(col)
	row.addlast(col)
	row.addlast(col)



GW(Posted 2015) [#2]
To access an (string)item in a list of lists you would do something like:

String(TList(row.Last()).Last())

lists store items as 'Object'. If you want the item back out of the list you need to cast it back into its proper type.

You should probably explain what you're trying to do, because I can't conceive any possible reason that you want to nest lists this way. It will clunky and it's really inefficient.
Something like a 2d array of strings will problably get you there without all the pain.


local StringGrid:string[width, height]


Nennig(Posted 2015) [#3]
Hi GW,

Thank you so much for your answer.
I will give it a try. Here is my goal.

I have a TListView control with some data (musical notes) and I want the user to be able to insert a new row/note after the selected row/note by pressing a button.
My understanding is that, with the TListView available methods, I can't insert a new row in the middle of my data, only at the end but that is not good enough for my needs.

I was hoping to use the first list to store the columns and the second to store the rows.
I would then populate the TListView rows and columns based on these two lists.

I intented to leverage the fact that you can insert a new element in the middle of a TList (InsertAfterLink).

I know, its very cumbersom but that is the only idea that I could come up with.
Many thanks for your help. I will work on your suggestion tomorrow.


Henri(Posted 2015) [#4]
Hi,

by using addListviewItem() - method as a template you could add a new method to your TListview which can insert new row in specified index like:
Method insertListViewItem(index:Int, text$[])
'insert full row from array to row specified in index
'------------------------------------------------------------------------------
	Local count:Int = CountGadgetItems(listBox)
	If index > count Then index = count
	If index < 0 Then index = 0
	Local curRow:Int = index
	'add first column & reset width
	Local oldWidth:Int = SendMessageW( ListboxHwnd, LVM_GETCOLUMNWIDTH ,0, 0)
	InsertGadgetItem(listBox, index, text$[0])
	If oldWidth > 0 Then columnHeading[0].Width=oldWidth 
	columnWidth
	
	For Local column:Int = 1 To text$.Length - 1
		Local ListboxHwnd:Int = QueryGadget(listBox, QUERY_HWND)
		Local ColItem:LVITEMW  = New LVITEMW
		ColItem.mask = LVIF_TEXT
		ColItem.iSubItem = column
		ColItem.iItem = curRow
		ColItem.pszText = Text$[column].ToWString()
		ColItem.cchTextMax =  Text$[column].Length + 1
		SendMessageW( ListboxHwnd, LVM_SETITEMW ,0, Int(Byte Ptr ColItem))
		MemFree(ColItem.pszText)
		ColItem = Null
	Next
End Method

-Henri

PS. addListviewItem() - method is originally by ghostdancer/jsp I believe.


Nennig(Posted 2015) [#5]
Hi Henri,

Thank you so much for this method. This is exactly what I was looking for.
You already helped me a lot in this project!

You made my day.
THANK YOU SO MUCH !