How can I select multiple individual grid cells?

I am looking for a grid of rows that allows me to select multiple cells at any point in the grid without adjoining each other, for example by pressing CTRL and clicking on different cells on the grid. Or if anyone knows how to do this with the standard Delphi TStringGrid.

Any pointers would be greatly appreciated.

+4
source share
1 answer

Despite the fact that there are many people with more capable abilities, since you have not received any answers, I thought I would try.

I do not know how to make a component for you. However, when you control a click on a cell, the OnSelectedCell event is raised. (I just tested this.) You can put the code in an event handler that adds the row and column of the cell to the list that you save from the selected rows and columns. Then, in the OnDrawCell event, select the cell:

procedure TForm1.StringGrid1DrawCell( Sender: TObject; ACol: Integer; ARow: Integer; Rect: TRect; State: TGridDrawState); begin if CellSelected( ARow, ACol) then // you write CellSelected() to refer to the list you're keeping begin StringGrid1.Canvas.Brush.Color := clYellow; StringGrid1.Canvas.FillRect(Rect); StringGrid1.Canvas.TextOut(Rect.Left,Rect.Top,StringGrid1.Cells[ACol,ARow]); end; end; 
+4
source

All Articles