Selecionar linhas no dbgrid

Delphi

20/08/2005

Como faço para clicar em um botao e selecionar todas as linhas de um dbgrid


Cruel

Cruel

Curtidas 0

Respostas

Gigatel

Gigatel

20/08/2005

Como faço para clicar em um botao e selecionar todas as linhas de um dbgrid


Oi tudo bem ?..vou te passar uma coisa seja mais útil...más caso queira mesmo usar um botão fique a vontade...que tal usar uma Tecla CTRL + A...ou CTRL+D para desmarcar...de qualquer forma está aí..no evento OnKeyPress coloque..


if key in [1, 4, 22] then
  begin
    DBGrid1.DataSource.DataSet.First;
    while not DBGrid1.DataSource.DataSet.Eof do
    begin
      {Ctrl+A}
      if key = 1 then
        DBGrid1.SelectedRows.CurrentRowSelected := true;

      {Ctrl+D}
      if key = 4 then
        DBGrid1.SelectedRows.CurrentRowSelected := false;

      {Ctrl+I}
      if key = 22 then
        DBGrid1.SelectedRows.CurrentRowSelected := not DBGrid1.SelectedRows.CurrentRowSelected;

      DBGrid1.DataSource.DataSet.Next;


espero ter ajudado...


GOSTEI 0
Marco Salles

Marco Salles

20/08/2005

So acrescentando :

primeiramente vc precisa passar para true a propriedade
Options.dgMultiSelect

Depois é conveniente usar a Propriedade DisableControls e enableControls

So acrescentando veja a diferença ... Qaunto maior os dados na tabela maior sera a diferença

procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
var
 BookMark:TBookMarkStr;
begin
  if key in [1, 4, 22] then
    begin
      BookMark:=Table1.Bookmark;
      Table1.disablecontrols;
      DBGrid1.DataSource.DataSet.First;
      while not DBGrid1.DataSource.DataSet.Eof do
        begin
         {Ctrl+A}
          if key = 1 then
            DBGrid1.SelectedRows.CurrentRowSelected := true;

        {Ctrl+D}
          if key = 4 then
            DBGrid1.SelectedRows.CurrentRowSelected := false;
        DBGrid1.DataSource.DataSet.Next;
       end;
      Table1.enablecontrols;
      Table1.Bookmark:=BooKmark;
   end;
end;



GOSTEI 0
Cruel

Cruel

20/08/2005

Obrigado pelas dicas


GOSTEI 0
POSTAR