Recent

Author Topic: StringGrid deselect rows (multiselect)  (Read 1481 times)

TomTom

  • Full Member
  • ***
  • Posts: 170
StringGrid deselect rows (multiselect)
« on: November 15, 2021, 12:57:43 pm »
Hi, im working on small application that loads a CSV into stringgrid. Then I have few options to filter this csv file. What I need is to be able to deselect (with CTRL) some selected rows (lets say selected by mistake). So for example.


ROW 1 <- SELECTED
ROW 2 <- SELECTED
ROW 3 <- SELECTED
ROW 4 <- SELECTED
ROW 5 <- SELECTED
ROW 6 <- SELECTED

I want to deselect ROW 3. How can I achieve that by clicking on this row? I know I can check if its selected (StringGrid1.isCellSelected), but how can I remove this part of selection? I think I would also need to remove this row from StringGrid1.selectedRange (I would need to somehow find right index for this).... Or maybe i don't know...


jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: StringGrid deselect rows (multiselect)
« Reply #1 on: November 16, 2021, 02:23:32 am »
Try using columns instead within the strnigGrid..

For the first column you can use a CheckBox button where you can toggle the state of that Row.

There are a couple of things you need to know about this however, one is that all the check mark states are stored in an array somewhere, they are not stored in the grid so there are events in the grid where it ask you the current state and if you have the grid in goEditor then you can toggle but what this does is calls the OnSetCheckBoxState where  you need to update your array of values, otherwise the toggle state will get reread from your array and just revert back by using the OnGetCheckBoxState.

 This first column will be set to a CheckBox button and the rest of the columns you need will be set to Auto.

 I know its a lot to take in but you may want to experiment a bit..

 Or  you could do the String grid in ownerDraw mode where you can do  your own highlighting but you still need to keep an external array active of the selected states. At least you will be able to color your backgrounds to reflect selected states.

 I tell you this because from what I know the current state of the grid does not allow to have multiple patched selections. of course I could be wrong about this, it won't be the first.




The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018