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