Recent

Author Topic: How to mimic a Bookmark in TStringGrid?  (Read 1602 times)

John Landmesser

  • New Member
  • *
  • Posts: 31
How to mimic a Bookmark in TStringGrid?
« on: November 17, 2021, 10:35:48 pm »
I want to add a Footer-Row to a TStringGrid by code and "bookmark" this row so i can restore it when the Grid was sorted.

Any ideas?

Thank you for any tipps!

MarkMLl

  • Hero Member
  • *****
  • Posts: 6682
Re: How to mimic a Bookmark in TStringGrid?
« Reply #1 on: November 18, 2021, 08:32:51 am »
What do you mean: a separate control as a status line, or set the state of the stringgrid so that the specified line is visible?

Assuming the second case, I've always found that type of scrolling etc. to be problematic and you might find it depends on the widget set (at which point I have to highlight that you've said absolutely nothing about what OS etc. you're using). I think the first thing you've got to decide is how you're going to mark the "special" line, since the index will almost certainly be changed by the sort operation.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: How to mimic a Bookmark in TStringGrid?
« Reply #2 on: November 18, 2021, 09:50:21 am »
Hi!

I have fought with this idea and found 2 solutions:

1. Use the OndrawCell event. Overpaint the last visible row with your status line.

2. Take a second stringGrid with no fixed row and only one row. Copy the column design from the first stringGrid . Place it below the "real" StringGrid.

Winni


Thaddy

  • Hero Member
  • *****
  • Posts: 14359
  • Sensorship about opinions does not belong here.
Re: How to mimic a Bookmark in TStringGrid?
« Reply #3 on: November 18, 2021, 10:18:56 am »
What you need is called a "stack" and is very basic computer science.
An example you might use is TReCall, which is a "fancy" stack. (Ok, it is a stack)

https://www.freepascal.org/docs-html/current/rtl/classes/trecall.html
You may also read up on (de)queues, which are similar but reverse order.

(I am a bit annoyed about other responses.. >:D, wrong foot, bed.. )

TReCall can be used to implement bookmarks, not emulate or mimic.....
« Last Edit: November 18, 2021, 10:34:46 am by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

John Landmesser

  • New Member
  • *
  • Posts: 31
Re: How to mimic a Bookmark in TStringGrid?
« Reply #4 on: November 18, 2021, 11:34:28 am »
Hi!

I have fought with this idea and found 2 solutions:

1. Use the OndrawCell event. Overpaint the last visible row with your status line.

2. Take a second stringGrid with no fixed row and only one row. Copy the column design from the first stringGrid . Place it below the "real" StringGrid.

Winni

I think i take your 1. solution, because the original Data of StringGrid will never be changed by the new footer-line!


The solution with real Bookmarks seemes to be also a solution, but potentially too complicated for a noob like me :-)

Thanks to all the replies!
« Last Edit: November 18, 2021, 01:42:08 pm by John Landmesser »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11445
  • FPC developer.
Re: How to mimic a Bookmark in TStringGrid?
« Reply #5 on: November 18, 2021, 01:52:22 pm »
Mark the bookmark line somehow (e.g. in objects[]) and change the compare routine of the sort in a way that the bookmark line is always last?

jamie

  • Hero Member
  • *****
  • Posts: 6128
Re: How to mimic a Bookmark in TStringGrid?
« Reply #6 on: November 18, 2021, 03:23:15 pm »
I would embed two grid within a panel so that panel would be the only border.
Anchore the second grid to the bottom and maintain grid sizes as the first.
Hide the second grid until needed and populated it.
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018