开发者

How can I select multiple individual cells of a string grid?

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 wou开发者_如何学Cld be gratefully received.


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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜