Listbox

Hello,
how can i give a Method Listbox1.Rows to add a row from inside my Method?
(without giving the Method the whole Listbox)

I do not understand. The LR says:

Allows you to iterate through all the rows in a ListBox.

[quote=472770:@Emile Schwarz]I do not understand. The LR says:

Allows you to iterate through all the rows in a ListBox.

yes, but why i can’t use a list somewhere in a oop language.
its by design?

[quote=472783:@Markus Rauch]yes, but why i can’t use a list somewhere in a oop language.
its by design?[/quote]
You can use it anywhere it’s in scope. There’s some information about scope here https://documentation.xojo.com/getting_started/object-oriented_programming/oop_design_concepts.html#Encapsulation but scope was one of the things I found easier to learn by playing with it.

I’m not sure entirely understand what problem you’re running into though. Maybe an example project to show?

You can’t manipulate the listbox data directly, you have to use AddRow, AddRowAt, RemoveRowAt etc. the Rows function is returning a copy of the data. Manipulating it has no effect on the ListBox.

I think so too but i not expect this in a oop language.

i would expect this

Var items(2) As String
items(0) = "Row A"
items(1) = "Row B"
items(2) = "Row C"

listbox1.Rows = items

Where in the LR did you learned that ?

You could always add that functionality to a subclass…
Create a subclass of listbox and add a method:

Public Sub rows(assigns rows() as string) self.initialvalue = join(rows,chr(13)) End Sub

Listbox doesn’t provide that behavior by default but you can always submit a feature request via Feedback

[quote=472793:@Markus Rauch]I think so too but i not expect this in a oop language.

i would expect this

[code]
Var items(2) As String
items(0) = “Row A”
items(1) = “Row B”
items(2) = “Row C”

listbox1.Rows = items
[/code][/quote]
Ah! That could be quite useful though. The way Listbox currently works you can set a single row at once in that manner, but I’m not aware of it being able to do multiple rows like that. I suppose you could write an extends method to do so, but it would be a reasonable feature request in my book. Edit: this is exactly what Jim said!

[quote=472795:@jim mckay]You could always add that functionality to a subclass…
Create a subclass of listbox and add a method:
Listbox doesn’t provide that behavior by default but you can always submit a feature request via Feedback[/quote]
thats true. thank you.

i think i should use subclass more often.

You should! Subclassing is great. Knowing when to is also just as valuable. In this situation I think an extends might be of more general use. It would enable the functionality on any Listbox and wouldn’t require you change any control superclasses.

This might work, but I wrote it in the post editor so you should review it!

[code]Global Sub AddRows(extends oLB as Listbox, paramarray arsRows() as String)
for ti as Integer = 0 to arsRows.Ubound
oLB.AddRow(arsRows(ti))

next ti
End Sub[/code]