如何选择字符串网格的多个单个单元格?

时间:2010-08-30 22:38:55

标签: delphi tstringgrid

我正在寻找一个字符串网格,它允许我在网格中的任何地方选择多个单元格而不会相互邻接,例如按下CTRL并单击网格上的各个单元格。或者,如果有人知道如何使用标准的Delphi TStringGrid执行此操作。

感激地收到任何指针。

1 个答案:

答案 0 :(得分:4)

虽然这里有很多能干的人,但由于你没有得到任何答案,我想我会试一试。

我不知道让组件为您执行此操作的方法。但是,当您按住Control键单击某个单元格时,将调用事件OnSelectedCell。 (我刚测试过。)您可以将代码放在一个事件处理程序中,该处理程序将单元格的行和列添加到您保留所选行和列的列表中。然后,在OnDrawCell事件中,突出显示单元格:

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;
相关问题