Lazarus

Programming => LCL => Topic started by: Focus77 on June 08, 2020, 10:14:11 pm

Title: [SOLVED]DBGrid, the cursor won't move to the persistent field.
Post by: Focus77 on June 08, 2020, 10:14:11 pm
Hi every body!

I have a dbgrid with 5 fields+a persistent field.

Autoadvance is at aaRightDown.

I  use RETURN to move between the columns .

But when the cursor is on the fifth column, it would not move to the persistent one. :(

is it a bug?
Title: Re: DBGrid, the cursor won't move to the persistent field.
Post by: jamie on June 08, 2020, 11:12:18 pm
Isn't a persistent field a Read only? if so then what good would be the cursor there ?
Title: Re: DBGrid, the cursor won't move to the persistent field.
Post by: Focus77 on June 08, 2020, 11:40:18 pm
Hi there

Of course the persistent field is a read only, but the cursor must cross it, in order to get
the next row.

for this I used the next code:
Code: Pascal  [Select][+][-]
  1. procedure TF_MAINFORM.DBGrid2KeyDown(Sender: TObject; var Key: Word;
  2.   Shift: TShiftState);
  3. begin
  4.   if key=VK_RETURN then
  5.      if DBGrid2.SelectedColumn.Index=4 then
  6.       DBGrid2.SelectedIndex:=5;
  7. end;  
Title: Re: DBGrid, the cursor won't move to the persistent field.
Post by: jamie on June 09, 2020, 12:04:03 am
maybe you should be cycling the columns each time you move up or down and always check for the field type and if not desirable then go to the next one until you fine one that is ..

 if you come to the end before you find one then you just don't move …

Title: Re: DBGrid, the cursor won't move to the persistent field.
Post by: Focus77 on June 09, 2020, 10:53:49 pm
Hi every one !

@jamie
In fact the only fields I can input the data are 1,2 and 3.

the code became:
Code: Pascal  [Select][+][-]
  1. procedure TF_MAINFORM.DBGrid2KeyDown(Sender: TObject; var Key: Word;
  2.   Shift: TShiftState);
  3. begin
  4.   if key=VK_RETURN then
  5.      if DBGrid2.SelectedColumn.Index<3 then
  6.       DBGrid2.SelectedIndex:=DBGrid2.SelectedIndex+1
  7.       else
  8.       begin
  9.       DBGrid2.SelectedIndex:=1;
  10.       if not MDT.T_NOTE.EOF
  11.       then MDT.T_NOTE.Next
  12.       end;
  13.  end;      
TinyPortal © 2005-2018