Recent

Author Topic: Setting TStringGrid extended selections programmatically  (Read 377 times)

Perico Palotes

  • Newbie
  • Posts: 2
Setting TStringGrid extended selections programmatically
« on: March 29, 2023, 06:40:17 pm »
Hi,

I'm trying to create a table in which the user can select a number of rows, which may not be contiguous, and then move them up/down the table by clicking on an up or down button.

I'm using TStringGrid for this, and the problem I'm having is that I can't find any way to modify the selections after the move, so the items that were selected before continue being selected, in case the user wants to keep clicking on the button to move the items further.

I'm implementing this functionality by iterating through
Code: Pascal  [Select][+][-]
  1. GrdTable.SelectedRange
and within this, through the range of rows and then calling
Code: Pascal  [Select][+][-]
  1. GrdExecTable.ExchangeColRow(False,j-1,j)
for example, to move the contents of row "j" up.

My grid options are
Code: Pascal  [Select][+][-]
  1. [goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goRowSelect,goSmoothScroll,goFixedColSizing,goCellEllipsis]
Code: Pascal  [Select][+][-]
  1. ExtendedSelect=True
Code: Pascal  [Select][+][-]
  1. RangeSelectMode=rsmMulti


I thought that maybe repeatedly setting
Code: Pascal  [Select][+][-]
  1. GrdTable.Selection
would allow me to re-create the multiple selection ranges, but a new value overwrites the previous one.

Am I missing something, or there really is no provision to re-create these selections from code? Seems odd to me.

Thanks.

Blaazen

  • Hero Member
  • *****
  • Posts: 3234
  • POKE 54296,15
    • Eye-Candy Controls
Re: Setting TStringGrid extended selections programmatically
« Reply #1 on: March 29, 2023, 08:31:08 pm »
SelectedRange is read-only property and there are no methods to manage it (there is ClearSelection but no AddToRangeSelect etc.).

If I did not miss anything I see no way to how do it (especially by code).

It would be tricky to implement those features to StringGrid since there are many setting an properties that affect Selections.

Maybe KGrid could be capable to do it, I don't know.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

jamie

  • Hero Member
  • *****
  • Posts: 5362
Re: Setting TStringGrid extended selections programmatically
« Reply #2 on: March 29, 2023, 11:36:16 pm »
There is always a way!  :D

Use OwnerDraw mode of the grid and draw the cells yourself.

Use the fixed columns to the left to mark the status of the line.

You can even use the Object pointers in the strings as storage for indicators.

 I believe what you are looking for is a simple way to mark the lines you wish to move and keep them marked to where they end up.

  If I wasn't so tired from fighting world hunger, I might even be inclined to write you something!
The only true wisdom is knowing you know nothing

Blaazen

  • Hero Member
  • *****
  • Posts: 3234
  • POKE 54296,15
    • Eye-Candy Controls
Re: Setting TStringGrid extended selections programmatically
« Reply #3 on: March 30, 2023, 12:33:31 am »
Then it would be easier to use TDrawGrid.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Perico Palotes

  • Newbie
  • Posts: 2
Re: Setting TStringGrid extended selections programmatically
« Reply #4 on: March 30, 2023, 10:24:48 am »
Thanks, guys, for confirming it's not an existing feature.
To be honest it's not worth the effort of doing the drawing myself. I think I'll use a list and combine all the cells into a single string... Not very elegant, but will do the job. It's read only data after all, I don't require editing.

 

TinyPortal © 2005-2018