Ver Mensaje Individual
  #4  
Antiguo 13-02-2009
Avatar de fjcg02
[fjcg02] fjcg02 is offline
Miembro Premium
 
Registrado: dic 2003
Ubicación: Zamudio
Posts: 1.410
Reputación: 22
fjcg02 Va camino a la fama
Para orientarte 'un poco'
Previamente he creado un campo en el dbgrid titulado 'Seleccionado'
Este campo no tiene asociado campo de la bbdd y es el primero de todos
Además mecesitas un memo con nombre Memo1. Puedes sustituirlo por un stringlist. A tu gusto.
Importante, el grid no permite editar. No sé que pasaría si fuese posible la edición!!

Pintado del grid. Si el id está en la lista, se escribe el checkbox y se pone en negrita toda la fila. Si no lo está
Código Delphi [-]
procedure TFSelPartidas.DBGrid1DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
var R:TREct; longitud, selecc: integer;
begin
Selecc:= 0;
// utilizo un memo para hacer de lista de id's de registros modificados ¿?
if  memo1.LineS.IndexOf(QTarifas.FieldByName('IdTarifa').AsString) >= 0 then
  begin
    (Sender as TDBGrid).Canvas.Font.Style:=[fsbold];
    (Sender as TDBGrid).Canvas.FillRect(Rect);
    Selecc:= DFCS_CHECKED;
  end
else DBGrid1.Canvas.Font.Style:=[];
   if Column.Title.Caption= 'Seleccionado' then 
// si es el campo indicado, pinto un check seleccionado o no en base al valor de selecc
        DrawFrameControl(DBGrid1.Canvas.Handle,REct, DFC_BUTTON, DFCS_BUTTONCHECK or Selecc)
    else
       (Sender as TDBGrid).DefaultDrawColumnCell(Rect, DataCol, Column, State);

end;
Para incluir los id's en el memo utilizo el siguiente procedimiento
Código Delphi [-]
procedure TFSelPartidas.DBGrid1KeyPress(Sender: TObject; var Key: Char);
var posicion: integer;
begin
if (key = ' ') and ( not WEdicion) then // si se pulsa espacio, se añade o borra el id
begin
  posicion:= memo1.LineS.IndexOf(QTarifas.FieldByName('IdTarifa').AsString);
 if posicion < 0 then Memo1.Lines.Add(QTarifas.FieldByName('IdTarifa').AsString)
 else Memo1.Lines.Delete(posicion);
 DBGrid1.Repaint;
end;
if not WEdicion then
StatusBar1.PAnels[0].Text:= 'Seleccionadas '+inttoStr(Memo1.lines.Count)+' partidas';

end;
También si clickamos sobre el checkbox de la fila seleccionamos o seleccionamos
Código Delphi [-]
procedure TFSelPartidas.DBGrid1CellClick(Column: TColumn);
var key:  char;
begin

if Column.Title.Caption= 'Seleccionado' then
begin
  key := ' ';
  DBGrid1KeyPress(DBGrid1, key);
end;
end;
La solución queda cuanto menos 'elegante'
Suerte y saludos
__________________
Cuando los grillos cantan, es que es de noche - viejo proverbio chino -
Responder Con Cita