What rows are selected in TStringGrid? (rangeselect & rowselect set to true) lazarus / 31-LCL ---------------------------------------------------------------------- stem · 2017-11-12 21:04 Hi, I have a StringGrid with goRangeSelect enabled and goRowSelect enabled. How can I find out what rows are selected? (I need to know, for example, that rows 1, 5, 9, 10 and 11 are selected.) Thank you! stem ---------------------------------------------------------------------- Mike.Cornflake · 2017-11-12 21:24 Fun question :-)   How to find the selected rows... Not tested, but a quick dive into the source code and I found SelectedRangeCount and SelectedRange... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Uses  Math;...var  oRange: windows.RECT;begin  For i := 0 To StringGrid1.SelectedRangeCount-1 Do  Begin    oRange := StringGrid1.SelectedRange[i];     if InRange(1, oRange,Top, oTop.Bottom) Then      // Row 1 Selected... (but do test, might be 0 you need to check for instead of 1)  End;End; Windows.RECT has a Top and a Bottom.  That'll most likely represent the Top Row and Bottom Row of each set of selected rows.  Probably 0 based, that'll need to be tested So the next part of your questions is how to see if a collection of sets contains items in a different collection of sets.  Ummm, stand by, I need to google :-) Update: See modified code above.  "Sets" turns out to be a silly word to google, end up with enumerated types.  So I went with the simpler code above, and I've leave it to others to answers to answer how to find if [1, 5, 9, 10, 11] is in [Selection1.Top..Selection1.Bottom, Selection2.Top..Selection2.Bottom...].  I admit to being muchly intrigued myself ---------------------------------------------------------------------- wp · 2017-11-12 22:01 Windows.Rect? No, a plain old TRect or, in the context of grids, TGridRect is all you need. The grid's SelectedRange is an array of TRect which has the row/column indexes (yes, zero-based) of the selected cell ranges in its Left/Top/Right/Bottom elements. In case of a selected row, the selection extends from the first to the last column index. Look at attached demo. ---------------------------------------------------------------------- Mike.Cornflake · 2017-11-12 22:10 Quote from: wp on November 12, 2017, 11:01:52 pmWindows.Rect? Hmmm, That's what Code Completion put in.  But yes, looking at the code TGridRect is indeed what it should have been.  Hmmm, looking down the rabbit hole, I see why Code Completion put in Windows.RECT:  on Windows TGridRect is Windows.TRect, which is in turn TRECT, which is ultimately RECT. ---------------------------------------------------------------------- stem · 2017-11-13 11:51 Quote from: Mike.Cornflake on November 12, 2017, 10:24:20 pmFun question :-)   How to find the selected rows... Not tested, but a quick dive into the source code and I found SelectedRangeCount and SelectedRange... It works, thank you!  stem