Listbox.selected

Hi,
I have a listbox and some rows on it.
is there any ways how to find out if the user select more than a row in a multiselect listbox.

thanks
arief

ListBox.Selected - Xojo Documentation

See Getting the list of selected rows

Var selectedRows() As Integer // Will hold the index of each selected row

For row As Integer = 0 To ListBox1.LastRowIndex
  If ListBox1.Selected(row) Then
    selectedRows.AddRow(row) // This row is selected
  End If
Next

Hi,

Will it work in older version of xojo ?
I am still using 2018r4.

thanks
arief

If you use the in built language reference (edit>options>use built-in documentation) then you can search your local documentation for the same page(listbox.selected) which will include the correct edition of the code for the version of xojo you’re using, so you’ll need:

Dim selectedRows() As Integer // Will hold the index of each selected row

For row As Integer = 0 To ListBox1.ListCount - 1 // Rows are zero-based
  If ListBox1.Selected(row) Then
    selectedRows.Append(row) // This row is selected
  End If
Next

I want to explain my goals,

I have a listbox with some rows, I want to change the value of the listbox while the user is selecting more than a row.
here is the code,

    dim o as integer
    for o = 0 to listbox1.liscount-1

    if listbox1.selected(o) then 'select more rows by pressing Ctrl button
    label1.text="user select multi rows"
    'replace the value of listbox
    else
    label1.text="user select 1 row only"
    'do nothing
    end if

thanks
arief

You want to change the values of multiple rows all at the same time, the multiple rows that are currently selected?

Do you want to compute the values found in the selected Rows and put the result into another Cell ?

Listbox.selcount will tell you how many rows are selected.

1 Like

thanks, this is the one.

regards,
Arief