Página 1 de 1

ListView / delete/insert / nIndex

Publicado: Lun Dic 23, 2024 7:15 pm
por Hurricane
Hi team,
in my application there is a selection option and I wanted to change the position of the items. So I used:

Código: Seleccionar todo

   nIndex:=oItem:nIndex
   oItem:Delete() // ::nIndex:=0
   oItem:=::oListView1:InsertItem( oItem:cText,,,,, oItem:lChecked, nIndex+1 )
LISTVIEW.png
LISTVIEW.png (14.05 KiB) Visto 15857 veces
I noticed that after deletion or insertion, some items will have outdated nIndex.
In the image, I only clicked once on item 2, which moved it, but...

Is there any alternative?
If you want, I can send this small example.

Re: ListView / delete/insert / nIndex

Publicado: Lun Dic 23, 2024 8:40 pm
por ignacio
Hi,

I'm afraid 'nIndex' is useless for your purpose when you delete and insert items. The time consuming of reordering all the items is useless.

Try with something like this:

Código: Seleccionar todo

METHOD nPos()    INLINE AScan( ::oParent:aItems, {|v| v == Self } )
Regards,

Re: ListView / delete/insert / nIndex

Publicado: Mar Dic 24, 2024 1:30 am
por Hurricane
Thank you Ignacio.

unfortunately it didn't work.
I've attached a small example.

One alternative I used was to just change the values, without deleting/inserting items, until I found a better solution.

Re: ListView / delete/insert / nIndex

Publicado: Jue Dic 26, 2024 5:53 pm
por ignacio
Hi,

I'm afraid there is not an easy solution to your problem. The nIndex property should be considered a creation order number, Just that. If you take a look a the code you will that indeed when the record is <<inserted>> on the control, the underlying array does not take into account. The best and only solution for your own use, is to use the cargo property to do the job.

Regards,