Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   C++ Builder (https://www.clubdelphi.com/foros/forumdisplay.php?f=13)
-   -   Texto celda pulsada en un ListView (https://www.clubdelphi.com/foros/showthread.php?t=95636)

chinchan 01-04-2022 19:13:41

Texto celda pulsada en un ListView
 
Hola. Necesitaría sacar el texto de la celda pulsada por el ratón en un ListView. Es decir, quiero identificar que celda he seleccionado dentro de un ListView. Muchas gracias

Casimiro Notevi 02-04-2022 11:51:33

Si lo que quieres es mostrar el texto (caption) de los items que están seleccionados (checked), entonces esto te puede servir:
Código Delphi [-]
procedure TForm1.ListView1Click(Sender: TObject);
begin
  VerSeleccionados;
end;

procedure TForm1.VerSeleccionados;
var
  Seleccionados: TStringList;
  i: Integer;
begin
  Seleccionados := TStringList.Create;
  try
    for i := 0 to ListView1.Items.Count - 1 do
      if ListView1.Items[i].Checked then
        Seleccionados.Add(ListView1.Items[i].Caption);

    memo1.Text := Seleccionados.Text;
  finally
    Seleccionados.Free;
  end;
end;


escafandra 03-04-2022 10:45:03

Escribí una clase para copiar cualquier campo (Caption y SubStrings) de un ListView al portapapeles. Quizás te oriente.
ListViewCopy

Saludos.

ecfisa 03-04-2022 19:42:11

Hola.

Otra opción para capturar el texto del ítem ante el click del ratón:
Código Delphi [-]
...
uses CommCtrl;

function GetListViewSubItem( LView: TListView ): string;
var
  Item: TListItem;
  Info: TLVHitTestInfo;
  Inx: Integer;
begin
  Info.pt := LView.ScreenToClient( Mouse.CursorPos );
  Inx := ListView_SubItemHitTest( LView.Handle, @Info );
  Result := '';
  if Inx <> -1 then
  begin
    Item:= LView.Items[Inx];
    if Info.iSubItem = 0 then
      Result := Item.Caption
    else
      Result:= Item.SubItems[Info.iSubItem-1];
  end;
end;
Ejemplo de uso:
Código Delphi [-]
procedure TForm1.ListView1Click( Sender: TObject );
begin
  Caption := GetListViewSubItem( ListView1 );
end;

Saludos :)

escafandra 07-04-2022 00:02:54

Estoy viendo que este es el foro de C++ Builder así que por si hubiese dificultades voy a traducir el código que expone ecfisa:


Código PHP:

String GetListViewSubItem(TListView *LV)
{
  
LVHITTESTINFO Info;
  
TListItem *Item;
  
int Index;
  
String Result "";

  
Info.pt LV->ScreenToClient(Mouse->CursorPos);
  
Index   ListView_SubItemHitTest(LV->Handle, &Info);
  if(
Index != -1){
    
Item LV->Items->Item[Index];
    if(
Info.iSubItem == 0)
      
Result Item->Caption;
    else
      
Result Item->SubItems->Strings[Info.iSubItem-1];
  }
  return 
Result;


Código PHP:

void __fastcall TForm1::ListViewClick(TObject *Sender)
{
  
Caption GetListViewSubItem(ListView);  



Saludos.


La franja horaria es GMT +2. Ahora son las 00:32:07.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi