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;
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
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 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