In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.

Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.

ListView / delete/insert / nIndex

Xailer English public forum
Responder
Avatar de Usuario
Hurricane
Mensajes: 278
Registrado: Mar Mar 24, 2015 10:21 am
Ubicación: Brasil
Contactar:

ListView / delete/insert / nIndex

Mensaje 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 15808 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.
Avatar de Usuario
ignacio
Site Admin
Mensajes: 9439
Registrado: Lun Abr 06, 2015 8:00 pm
Ubicación: Madrid, Spain
Contactar:

Re: ListView / delete/insert / nIndex

Mensaje 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,
Ignacio Ortiz de Zúñiga
[OZ Software]
https://www.ozs.es
--
[Equipo de Xailer / Xailer team]
https://www.xailer.com
Avatar de Usuario
Hurricane
Mensajes: 278
Registrado: Mar Mar 24, 2015 10:21 am
Ubicación: Brasil
Contactar:

Re: ListView / delete/insert / nIndex

Mensaje 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.
Adjuntos
listview_move_item.zip
(2.78 KiB) Descargado 263 veces
Avatar de Usuario
ignacio
Site Admin
Mensajes: 9439
Registrado: Lun Abr 06, 2015 8:00 pm
Ubicación: Madrid, Spain
Contactar:

Re: ListView / delete/insert / nIndex

Mensaje 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,
Ignacio Ortiz de Zúñiga
[OZ Software]
https://www.ozs.es
--
[Equipo de Xailer / Xailer team]
https://www.xailer.com
Responder