Delphi TStringGrid multi select, determining selected rows

一个人想着一个人 提交于 2019-12-07 14:16:35

问题


Is there anyway to determine which rows are currently selected in a multi-select TStringGrid, or a TCustomGrid for that matter. A property would be ideal.

I know that there is the gdSelected property that gets set in the DrawCell event,

procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState);

I can check AState for gdSelected, and keep track of this in an array somewhere, but this seems kludgey.


回答1:


I guess you are talking about a range-select string grid, that is, a string grid with goRangeSelect in Options. Then you can use the Selection property. This is (essentially) a TRect in which you can find the upper-left and lower-right cell in the range selection.




回答2:


Oooh, I'm use StringGrid.Selection.BottomRight.Y to determine rows and StringGrid.Selection.BottomRight.X for columns.




回答3:


Use string grid selection property StringGrid.Selection.top will give you the top selected row, StringGrid.Selection.bottomwill give you the end selected row, where the selection stops.

Example:

If you select from row 3 to row 6 in a string grid thenStringGrid.Selection.top will give you 3 as an output value StringGrid.Selection.bottom will give you 6 as an output value, and remaining values you can get by iterating from the top to bottom.



来源:https://stackoverflow.com/questions/5950918/delphi-tstringgrid-multi-select-determining-selected-rows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!