Ir al contenido


Foto

[RESUELTO] Problema insertando datos desde un listview


  • Por favor identifícate para responder
4 respuestas en este tema

#1 enecumene

enecumene

    Webmaster

  • Administrador
  • 7.419 mensajes
  • LocationRepública Dominicana

Escrito 13 agosto 2009 - 05:59

Pues eso, tengo un problema al intentar agregar un grupo de datos desde un Listview, el objetivo es agregar los datos que están seleccionados en un Listview, los datos las voy insertando a un ListBox, lo que tengo es lo siguiente:



delphi
  1. procedure TForm1.AgregaralalistadeReproduccin1Click(Sender: TObject);
  2. var i: Integer;
  3. begin
  4.   if grCanciones.SelCount > 0 then
  5.     begin
  6.         for pi := 0 to grCanciones.SelCount - 1 do
  7.         begin
  8.           AgregarALista(grCanciones.Items[pi].SubItems[8]);
  9.         end;
  10.       end;
  11. end;



Aquí­ estoy contando todos los items que están seleccionados e ir agregandolos con el procedimiento AgregarALista, que es el siguiente code:



delphi
  1. procedure TForm1.AgregarALista(sFullPath: String);
  2. var
  3.   obj : TmiObjeto;
  4.   sFileName : string;
  5. begin
  6.   obj := TmiObjeto.Create;
  7.   obj.sPath := sFullPath;
  8.   sFileName := '['+grCanciones.Items[pi].SubItems[2]+'] '+grCanciones.Items[pi].SubItems[3]+' - '+grCanciones.Items[pi].SubItems[1];
  9.   grLista.Items.AddObject(sFileName, TmiObjeto(obj));
  10. end;



Pero al intentar agregar esos datos me da el siguiente error:

---------------------------
Debugger Exception Notification
---------------------------
Project Jukebox.exe raised exception class EStringListError with message 'List index out of bounds ( 8 )'. Process stopped. Use Step or Run to continue.
---------------------------
OK  Help 
---------------------------


No sé qué hago mal

  • 0

#2 Héctor Randolph

Héctor Randolph

    501st Legion

  • Moderadores
  • PipPipPip
  • 664 mensajes
  • LocationMéxico

Escrito 13 agosto 2009 - 06:17

¿y cuántas columnas tiene ListView?

Al parecer la columna con í­ndice 8 no existe..

  • 0

#3 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.446 mensajes
  • LocationMéxico

Escrito 13 agosto 2009 - 06:22

Estas contando el Item como parte de los subitems, por lo que debes de contar de esta forma

0= Item
1..8= SubItems

Entonces la columna 8 es realmente la columna 7 :D

Salud OS

[off-topic]A ver si me explique, porque ni yo me entendi jajajajaj[/off-topic]
  • 0

#4 enecumene

enecumene

    Webmaster

  • Administrador
  • 7.419 mensajes
  • LocationRepública Dominicana

Escrito 13 agosto 2009 - 06:25

Ah vale, viendo como lo dices el asunto queda así­:

0 = Item
0..7 = Subitems

Ahora sí­ corre el asunto :D, gracias amigo (y)

Saludos.
  • 0

#5 enecumene

enecumene

    Webmaster

  • Administrador
  • 7.419 mensajes
  • LocationRepública Dominicana

Escrito 14 agosto 2009 - 06:12

Para quién lo necesite alguna vez, el code quedó de esta forma:



delphi
  1. Type
  2.   TMiObjeto = class(TObject)
  3.     sPath: String;
  4.   end;
  5.  
  6. procedure TForm1.AgregaralalistadeReproduccin1Click(Sender: TObject);
  7. var i: Integer;
  8.  
  9. procedure AgregarALista(sFullPath: String);
  10. var
  11.   obj : TmiObjeto;
  12.   sFileName : string;
  13. begin
  14.   obj := TmiObjeto.Create;
  15.   obj.sPath := sFullPath;
  16.   sFileName := '['+grCanciones.Items[i].SubItems[1]+'] '+grCanciones.Items[i].SubItems[2]+' - '+grCanciones.Items[i].SubItems[0];
  17.   grLista.Items.AddObject(sFileName, TmiObjeto(obj));
  18. end;
  19.  
  20. begin
  21.   if grCanciones.SelCount > 0 then
  22.     begin
  23.         for i := 0 to grCanciones.Items.Count -1 do
  24.         begin
  25.           if grCanciones.Items.Item[i].Selected then
  26.           AgregarALista(grCanciones.Items[i].SubItems[7]);
  27.         end;
  28.       end;
  29. end;



Me funciona de pelos ;).

Saludos.
  • 0




IP.Board spam blocked by CleanTalk.