Delete ListBox Folders + Indexed Rows when selected

I’ve been messing around with Xojo for a while and made a few projects, most of my problems are solved from the xojo docs, but im stuck now.
Currently i have a listbox with a few folders with some info indexed in and i had the thought of deleting the folder when a button is pressed as long as the folder is selected.

My Code:
ListBox1:
Cell Text Paint:

[code] if column = 0 then
g.Bold = true
g.TextSize = 14

			g.drawString me.Cell(row, 0), x, 20, g.Width - x, true
			
			g.Bold = false
			g.ForeColor = &c929292
			g.TextSize = 14
			
			Dim type As String = me.Cell(row, 2)
			Dim size As String = me.Cell(row, 3)
			
			g.DrawString (type, x, 40, g.width -x, false)
			g.DrawString (size, me.Width - 128, 40, g.Width - x, false)
			
			return true
	end[/code]

Open:

[code] Me.ColumnAlignmentOffset(0)= 96
Me.DefaultRowHeight = 64
me.ColumnType(0) = ListBox1.TypeCheckBox

	Listbox1.AddFolder "Folder"
	Listbox1.Cell(Listbox1.LastIndex, 1) = "Test"
	ListBox1.Cell(Listbox1.LastIndex, 2) = "Test"[/code]

and i have a button that is supposed to delete the folder when selected but that clearly doesn’t work and i’m nothing near a solution after hours of messing around with code.

thank you.

we could surely help if you provide the code in the action event of the button that does not work as expected …
all the code you posted is working !

[quote=347269:@Jean-Yves Pochez]we could surely help if you provide the code in the action event of the button that does not work as expected …
all the code you posted is working ![/quote]

i don’t have any code in the button since none of it was close in anyway so when i gave up, so the button is just functionless atm :confused:

So, you want to know how to write the code to delete the folder… etc.

yes please i’m actually so stuck i have no idea what to do anymore.

listbox1.RemoveRow(5)

If it’s a folder, set Expanded = False first.

im still stuck,

Listbox1.removerow(1) ListBox1.Expanded(1) = false

my code is still the same from my first post, but i have this in my button.
currently this is the only way the app runs without crashing on launch but it crashes as soon as i press the button… :confused:

ListBox1.Expanded(1) = false Listbox1.removerow(1)

Greg said to put the Expanded = false first, so why not try that?

And if you only have one row in the listbox, it’s row 0, not 1.

Or to delete all selected rows:

if lst.ListCount > 0 then For i As Integer = lst.ListCount-1 DownTo 0 If lst.Selected(i) Then If lst.RowIsFolder(i) And lst.Expanded(i) Then lst.Expanded(i) = False lst.RemoveRow(i) End If Next End If

For multi-row deletion, what Neil has presented is the most important aspect of such a method - you must remove from the highest numbered row down instead of from row 0 up. Removing from the bottom up will reorder the remaining rows and your selected row numbers will change.