How do I know if there is a selected row in the DBGrid?

0

How can I tell if there is a selected row in my DBGrid. In this case below:

Thepointerisselectedinthedataset,butIwantedtoknowwhenthegridlookslikethis:

In this case would it be only if it the line is "painted", if so how to know? I tried DBGrid.Focused and DBGrid.SelectedRows.CurrentSelected but it did not work.

    
asked by anonymous 14.07.2015 / 04:31

2 answers

1

I ended up finding that in this case we should work with grid , it would be:

DBGDados.Columns.Grid.Focused
    
15.07.2015 / 04:08
1

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

When I want to check it out I do this

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

CAUTION !!

DBGDados.Columns.Grid.Focused

Check 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;
    
30.12.2015 / 18:56