How to know if there is a line selected in Dbgrid?

Asked

Viewed 2,827 times

0

How can I know if there is a selected line in my Dbgrid. In this case below:

inserir a descrição da imagem aqui

The pointer is selected in the dataset, but I wanted to know when the grid is this way:

inserir a descrição da imagem aqui

In this case it would be only if it the line is "painted", if yes how to know? I tried DBGrid.Focused and DBGrid.SelectedRows.CurrentSelected but it didn’t work out.

2 answers

1


Eventually I discovered that in this case we should work with grid, would then be:

DBGDados.Columns.Grid.Focused

1

Yes, it would be if it is painted, but the first record already comes selected.

when I want to verify I do so

if query.FieldByName(campo_id).AsInteger >= 1 then
   // procedimento para realizar chamada de tela entre outros...

CARING!!

DBGDados.Columns.Grid.Focused

Checks if the focus is on the grid!!

If you want to change the color of the selected line you have this code

  if not odd(qyrBuscaBanco.RecNo) then            // deixa grid zebrado
     begin
        if not (gdSelected in State) then
           begin
              dbgrdBanco.Canvas.Brush.Color := clMoneyGreen;
              dbgrdBanco.Canvas.FillRect(Rect);
              dbgrdBanco.DefaultDrawDataCell(rect,Column.Field,state);
           end;
     end;

  with dbgrdBanco do                 // pinta a linha selecionada
       begin
          if DataSource.DataSet.State in [dsEdit, dsInsert, dsBrowse] then 
             begin
                if (Rect.Top = TStringGrid(dbgrdBanco).CellRect( DataCol ,TStringGrid(dbgrdBanco).Row).Top)
                    or( gdSelected in State)  then
                   begin
                      Canvas.FillRect(Rect);
                      Canvas.Brush.Color := [COR PARA A LINHA SELECIONADA];
                      DefaultDrawDataCell(Rect,Column.Field,State)
                   end;
             end;
       end;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.