Windows Desktop Listbox

Hi guys,

just doing my first tiny steps in Xojo.

I do have a problem with a kind of simple thing.
I want to select (like selcted with left mouse button) a row in a desktop listbox.

by google i get something like this: listbox.listindex = var(integer)

.listindex is not shown when pressing TAB, .index = x has no effect as far as i can see.

But this seems to have no effect in my code. (deleting a row in a listbox and i want (if exists) the first line be autoselected after deleting)

I use the labe text for debugging(live) which gives me 3 / -1 / -1 after deleting row #3

Label1.Text = TaskList.SelectedRowIndex.tostring
'secu
if TaskList.SelectedRowindex >= 0 then
  'delete selected row
  TaskList.RemoveRowAt(TaskList.SelectedRowIndex)
end if

Label1.Text = Label1.Text + "/" + TaskList.SelectedRowIndex.tostring

'secu
if TaskList.SelectedRowindex >= 1 then
  'set selection
  tasklist.index = 1
  tasklist.Refresh
end if
Label1.Text = Label1.Text + "/" + TaskList.SelectedRowIndex.tostring

So the remove sets the listindex to -1, how can i get it to another number by code ??

Thanks in advance for your help

Greets…mabbi

I think you want to use .SelectedRowIndex = 0

…shame on me just found it myself…

The second if-clause is wrong and prohibits the prgram from setting the selectedrowindex at all…

This works:

'secu
if TaskList.RowCount >= 0 then
  'set selection
  tasklist.SelectedRowIndex = 0
end if

Sorry for this ugly question in the first post…should have debugged it first and then asked in this forum.

greets…mabbi

Hi AlbertoD,

ty for your response…meanwhile i figured it out myself.

I was using various phrases in that false if-clause and just wondered, why nothing at all happend instead of debugging line by line which gave me an direct hint that the lines were never ever processed.

Greets…Mabbi

1 Like

Be aware that xojo introduced the “api2” a couple years ago. it is mostly a lot of renaming of events, properties and methods to make the languaje “look” more modern. listindex was the way to go a few years ago but now, expect all the sources on internet to be outdated and the ONLY one “valid” is the documentation:

https://documentation.xojo.com/index.html

Rather than Google, either click the question mark above the IDE, or go to the LR:
https://documentation.xojo.com