views:

102

answers:

1

I am looking for a string grid that allows me select multiple cells anywhere in the grid without them adjoining each other, e.g pressing CTRL and clicking on various cells over the grid. Or if anyone knows how to do this with the standard Delphi TStringGrid.

Any pointer would be gratefully received.

+1  A: 

Although there are a lot of better capable people here, since you haven't gotten any answers, I thought I'd give it a try.

I'm not aware of a way to have the component do this for you. However, when you Control-click a cell, the event OnSelectedCell is called. (I just tested that.) You could put code in an event handler that adds the cell's row and column to a list that you keep of the rows and columns that are selected. Then, in the OnDrawCell event, highlight 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;
Robert Frank
Hey, that's a working solution and I don't think that there are any that are easier to implement. So while there might be people who are more capable than you (Are you the one who is not the world's best programmer?) you got a working solution and an answer while all the others where still thinking about it.
dummzeuch
Sorry for the Belated reply,I have been on HolidayMany thanks for the exampleColin