Listbox Listindex

Hi,
I want to make the listindex of a listbox equal in selected row based with the listbox value while the user click it.

but there are some strange thing. I do experiment in two project. One is worked normally as expected.
but the second one, everytime I click the row, its selected all rows in second listbox.


dim g as integer
for g = 0 to Listbox1.ListCount-1
  dim g1 as integer
  for g1=0 to Listbox3.ListCount-1
    if Listbox1.Selected(g) then
      if Listbox1.cell(g,1)=Listbox3.cell(g1,1) then
        Listbox3.Selected(g1)=Listbox1.Selected(g)
      end if
    end if
  next
next

I put this code in change event. Xojo 2021.r1.1

thanks
arief

Try this:


dim g as integer
dim d as new dictionary

for g = 0 to Listbox1.ListCount-1
    if Listbox1.Selected(g) then d.value(Listbox1.cell(g,1)) = "selected"
next

for g = 0 to Listbox3.ListCount-1
 Listbox3.Selected(g)=  d.haskey(Listbox3.cell(g,1)) 

  //    or possibly
  //   if d.haskey(Listbox3.cell(g,1)) then  Listbox3.Selected(g)= true
  //    which will not UNSELECT any existing rows
next

Cool.
very fast…
its worked now.

thanks.

regards
arief