GARANTIR DESCONTO

Fórum Selecionar linhas no dbgrid #292423

20/08/2005

0

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


Cruel

Cruel

Responder

Posts

20/08/2005

Gigatel

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


Responder

Gostei + 0

20/08/2005

Marco Salles

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;



Responder

Gostei + 0

20/08/2005

Cruel

Obrigado pelas dicas


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar