請問DBGrid相關的問題(DBGrid1DrawColumnCell)。 |
缺席
|
t0288542
中階會員 發表:216 回覆:254 積分:94 註冊:2004-10-06 發送簡訊給我 |
請問各位前輩: 有個奇怪的問題,目前建立一個DBGRID需要的功能有三個功能。
第一。希望第一欄有個CHECKBOX
第二。希望DBGrid每一行可變顏色。
第三。針對某一欄位值為'Y'或'N'可單獨變顏色。
之前我單獨使用第一個功能都可以但結合第二和第三的功能。
現在卻發生問題。紅色字體為發生錯誤的地方。
麻煩大家。告訴我,那裡需要作修正。 procedure TFCSFCB01.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
const IsChecked : array[Boolean] of Integer =
(DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or DFCS_CHECKED);
var
DrawRect : TRect;
DrawState: Integer;
Canvas : TCanvas;
begin if SameText(Column.FieldName,'選擇') then
begin
DrawRect:=Rect;
InflateRect(DrawRect,-1, -1); if st.IndexOf(dbgrid1.fields[1].asstring) <> -1 then
DrawState := IsChecked[true]
else
DrawState := IsChecked[false]; DBGrid1.Canvas.FillRect(Rect);
DrawFrameControl(DBGrid1.Canvas.Handle, DrawRect,
DFC_BUTTON, DrawState); Canvas := (Sender as TDBGrid).Canvas;
if((Column.Field.DataSet.RecNo mod 2)=0) then
begin
Canvas.Brush.Color := clWindow;
Canvas.Font.Color :=Clblack;
end
else
begin
Canvas.Brush.Color := clInactiveCaptionText;
Canvas.Font.Color :=Clblack;
end;
Canvas.FillRect(Rect);
DBGrid1.DefaultDrawDataCell(Rect, Column.Field, State);
end; if (Column.Field.FieldName <> 'CB015') then Exit;
if (Column.Field.AsString ='己匯入') then
begin
Canvas := (Sender as TDBGrid).Canvas;
Canvas.Brush.Color := clRed;
Canvas.FillRect(Rect);
DBGrid1.DefaultDrawDataCell(Rect, Column.Field, State);
end;
end;
procedure TFCSFCB01.DBGrid1CellClick(Column: TColumn);
begin
dbgrid1.Invalidate;
if column.fieldname='選擇' then begin
if st.IndexOf(column.Grid.Fields[1].asstring) = -1 then
begin
st.add(column.Grid.Fields[1].asstring);
end
else begin
st.Delete(st.indexof(column.grid.fields[1].asstring));
end;
dbgrid1.Invalidate;
end;
if ( Copy(column.Grid.Fields[5].asstring,1,1)<>'Y' ) and
( Copy(column.Grid.Fields[5].asstring,1,1)<>'y' ) then
showmessage('目前未完工'); end;
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |