如何在DBGrid中選取某一欄改變整行的顏色(dgRowSelect 不能為True) |
尚未結案
|
shinjie
資深會員 發表:12 回覆:275 積分:287 註冊:2003-03-19 發送簡訊給我 |
請教各位大大一個問題:
因資料來源為BDE故無法使用DataSource1.DataSet.RecNo
因程式功能需求,dgRowSelect不能設為True 問題:要在DBGRID中,選擇某一欄時(if gdselected in state)要改變整行的
顏色。
謝謝各位的幫忙。 =========================================
程式有問題並不可怕,最怕是不知問題出在那
不知問題在那不可怕,更怕是不知如何問問題
寫程式要從最簡單的開始
------
我將在茫茫人海中尋訪我唯一之靈魂伴侶。 得之;我幸。不得;我命。 |
jimmy_wei
高階會員 發表:9 回覆:176 積分:147 註冊:2003-08-28 發送簡訊給我 |
|
jimmy_wei
高階會員 發表:9 回覆:176 積分:147 註冊:2003-08-28 發送簡訊給我 |
shinjie 你好:
procedure TFORM.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); var oGrid : TDBGrid; oDataSet : TDataSet; sFieldName :string; begin inherited; oGrid := Sender as TDBGrid; oDataSet := (Sender as TDBGrid).DataSource.DataSet ; if not oDataSet.Active then Exit; if oDataSet.RecordCount = 0 then Exit; if gdselected in state oGrid.Canvas.Brush.Color:=RGB(200, 100, 100); oGrid.DefaultDrawColumnCell(Rect, DataCol, Column, State); end;我又看了一下....我好像答非所問耶....傷腦筋 發表人 - jimmy_wei 於 2005/04/26 19:35:11 |
wameng
版主 發表:31 回覆:1336 積分:1188 註冊:2004-09-16 發送簡訊給我 |
簡單一點將 Options 中 dtMultiSelect := True;
dtAlwaysShowEditor := False; 或者
定義 Form1私有變數 RowID procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); var I :Integer; ARect: TRect; begin if not ADOQuery1.Active then Exit; With TStringGrid(DBGrid1),DBGrid1 do if gdSelected in state then begin RowID := Row; For I:=LeftCol to LeftCol VisibleColCount do if I<>(DataCol 1) then begin ARect := CellRect(I,Row); Windows.InvalidateRect(Handle, @ARect, True); end; end else if RowID=Row then begin ARect := CellRect(DataCol 1,Row); ARect.Right :=ARect.Left ColWidths[DataCol 1]; Canvas.Brush.Color := ClHighLight; Canvas.Font.Color := ClHighLightText; DefaultDrawColumnCell(ARect,DataCol,Columns[DataCol],[gdFocused]); end; end;仍有些瑕疵,如移動滑鼠滾輪[:]可能就會有殘影現象。 要解決此問題,可能要攔截 WM_MOUSEWHEEL 訊息。 自行補強一下吧。 參考。 |
shinjie
資深會員 發表:12 回覆:275 積分:287 註冊:2003-03-19 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |