Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   Saber al boton que se le dio click en un StringGrid (https://www.clubdelphi.com/foros/showthread.php?t=64950)

chico_bds 11-11-2009 07:50:59

Saber al boton que se le dio click en un StringGrid
 
Hola amigos teno el siguiente problema a ver si me pueden ayudar... a cada fila de un StringGrid le creo dos botones pero necesito saber como puedo hacer para en el evento onclick enviar un parametro con la fila a la que se le dio click....

Código Delphi [-]
while not (ds.Eof) do
begin

//ShowMessage(ds.FieldByName('nombres').AsString);

StringGrid1.Cells[0, contador] := ds.FieldByName('nombres').AsString;
StringGrid1.Cells[1, contador] := ds.FieldByName('apellidos').AsString;
StringGrid1.Cells[2, contador] := ds.FieldByName('cedula').AsString;
StringGrid1.Cells[3, contador] := ds.FieldByName('nombreArtistico').AsString;
StringGrid1.Cells[4, contador] := ds.FieldByName('clasificacion').AsString;
StringGrid1.Cells[5, contador] := ds.FieldByName('nacionalidad').AsString;

btn := TButton.Create(Self);
btn.Caption:= 'Modificar';
btn.Width:= 87;
btn.Parent:= StringGrid1;
btn.BoundsRect:= StringGrid1.CellRect(6, contador);

btnView := TButton.Create(Self);
btnView.Caption:= 'Formulario';
btnView.Width:= 87;
btnView.Parent:= StringGrid1;
btnView.BoundsRect:= StringGrid1.CellRect(7, contador);

Inc(contador);

ds.Next;

end;

Saludos desde ya muchas gracias

Neftali [Germán.Estévez] 11-11-2009 09:59:50

Lo más sencillo que se me ocurre es que utilices ta propiedad TAG (por ejemplo) del botón para marcar la fila donde se encuentra. Una vez pulsado el botón puedes recuperar el valor de ea propiedad.

Código Delphi [-]
...
btn := TButton.Create(Self);
btn.Caption:= 'Modificar';
btn.Width:= 87;
btn.Parent:= StringGrid1;
btn.BoundsRect:= StringGrid1.CellRect(6, contador);
btn.Tag := contador;

...
btnView := TButton.Create(Self);
btnView.Caption:= 'Formulario';
btnView.Width:= 87;
btnView.Parent:= StringGrid1;
btnView.BoundsRect:= StringGrid1.CellRect(7, contador);
btnView.Tag := contador;

En el OnClick puedes recuperar ese valor utilizando el Sender.

Código Delphi [-]

...
  if (Sender is TButton) then begin
    fila := TButton(Sender).Tag;
  end;
...

chico_bds 11-11-2009 18:52:26

Gracias
 
Amigo de antemo muchas gracias ahora estoy en la office... ya en la casa pruebo la solucion que me dices y te comento.


La franja horaria es GMT +2. Ahora son las 00:01:44.

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