TStringGrid问题:
  1、我要实现多行选择操作,选择多行后 怎么来操作我所选中得这几行数据?  2、怎么控制每行的字体颜色?StringGrid里得数据状态不一样,我想实现不同状态的数据所在行的字体颜色与其它行区分来!(如:已发工资的人为红色)
  
  小弟先谢了!!

解决方案 »

  1.   

    //StringGrid1.Selection表示所选择的区域,其Top和Bottom分别表示起始行和结束行
    //在onMouseUp里判断一下就知道哪几行被选中了
    procedure TForm1.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
     Memo1.Lines.Append('开始行是:'+IntToStr(StringGrid1.Selection.Top)+
      ',结束行是:'+IntToStr(StringGrid1.Selection.Bottom));
    end;//下面是一个偶数行涂红色,字体为绿色的例子
    //注意:千万不要再DrawCell方法里用Cells[ACol,ARow]:='***'为单元格文本赋值
    //因为它又会调用DrawCell方法,形成死循环
    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    begin
     if ARow mod 2=0 then
     begin
      StringGrid1.Canvas.Brush.Color:=clRed;
      StringGrid1.Canvas.Font.Color:=clGreen;
      StringGrid1.Canvas.FillRect(Rect);
      StringGrid1.Canvas.TextOut(Rect.Left+2,Rect.Top+2,'特殊');
     end
     else StringGrid1.Canvas.TextOut(Rect.Left+2,Rect.Top+2,'不特殊');
    end;
      

  2.   

    哦,颜色区分的问题我弄好了 我把canvas.brush.color 去掉就行了! 区域的选择 不连续怎么办,哦对了stringgrid好象是不是必须连续选择啊,不支持ctrl选择?