Recent

Author Topic: StringGrid Questions  (Read 641 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1278
StringGrid Questions
« on: December 31, 2022, 04:52:44 am »
I have 2 TSringGrids on a form with loaded data.

I would like to click on a row in a grid in using code.
I know the row and column. If I click on the column with the mouse it loads a second grid on the form with data. Can I do this all in code?

Thanks.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

dsiders

  • Hero Member
  • *****
  • Posts: 816
Re: StringGrid Questions
« Reply #1 on: December 31, 2022, 07:49:28 am »
I have 2 TSringGrids on a form with loaded data.

I would like to click on a row in a grid in using code.
I know the row and column. If I click on the column with the mouse it loads a second grid on the form with data. Can I do this all in code?

Thanks.

Write an OnSelectCell event hander in the first grid to do whatever you need to the second grid.
Preview Lazarus 2.3.0 documentation at: https://dsiders.gitlab.io/lazdocsnext

JLWest

  • Hero Member
  • *****
  • Posts: 1278
Re: StringGrid Questions
« Reply #2 on: December 31, 2022, 08:13:47 am »
i can see where the right grid would be loaded with the proper file but what about the left grid.

Don't I have to click a row on the left Grid to get the onSelectEvent to fire?
Thanks
 
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

KodeZwerg

  • Hero Member
  • *****
  • Posts: 1177
  • Fifty shades of code.
    • Delphi & FreePascal
Re: StringGrid Questions
« Reply #3 on: December 31, 2022, 09:57:43 am »
You are expressing yourself a little bit... unclear.
Please write down exactly how you wish that things shall happen.
Like "Click in Grid1 shall start action for Grid2", then we are what dsiders suggested, in an OnClick event.
Best would be to have a small demo app from you that helping people can just integrate things you are missing.
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

bytebites

  • Hero Member
  • *****
  • Posts: 546
Re: StringGrid Questions
« Reply #4 on: December 31, 2022, 11:11:41 am »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.grid1SelectCell(Sender: TObject; aCol, aRow: Integer;
  2.   var CanSelect: Boolean);
You can call  it as you wish
Code: Pascal  [Select][+][-]
  1. var select:boolean
  2. begin
  3.   grid1SelectCell(grid1,3,4,select)
  4. end;
  5.  

JLWest

  • Hero Member
  • *****
  • Posts: 1278
Re: StringGrid Questions
« Reply #5 on: December 31, 2022, 05:28:32 pm »
Hi All and a Happy new Year to all.

I think ByteBites may have got it.

Two Grids on a form. if I click a row on Grid1 a file will load in Grid2. If I then click a row in Grid2 it will display something a memo. Grid1, Grid2 and the memo are all unique and connected.
However, I don't want to do it with a mouse click but by executing code.

So Stringgrid1SelectCell(StringGrid1,1,4,select)

write an OnSelectCell event hander to click StringGrid2

@Kodezwerg If I can't make this work I'll write a demo
« Last Edit: December 31, 2022, 05:31:16 pm by JLWest »
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

howardpc

  • Hero Member
  • *****
  • Posts: 4117
Re: StringGrid Questions
« Reply #6 on: December 31, 2022, 08:52:46 pm »
Perhasps you're looking for something like the attached project?

JLWest

  • Hero Member
  • *****
  • Posts: 1278
Re: StringGrid Questions
« Reply #7 on: December 31, 2022, 09:08:18 pm »
@Howardpc - Happy New Year

I just compiled and ran. I think so.

It's really navigating around grids via code with two grids connected. And I think that's what you're code performs.

FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

 

TinyPortal © 2005-2018