日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

DELPHI的DBGRID有两个难点

發布時間:2025/3/20 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 DELPHI的DBGRID有两个难点 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

DELPHI的DBGRID有兩個難點:

一,每行都是一個BUTTON,且CAPTION不同

二,每行不同行高,且由用戶拖動而不同高的

這兩點我用CXGRID全做到了

一,

procedure TForm1.cxGrid1DBTableView1Column1CustomDrawCell(

? Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;

? AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);

var

? www: tbutton;

? i, j: integer;

begin

www:=nil;

? try

?

? for i := AViewInfo.GridView.Site.ComponentCount - 1 downto 0? do

? begin

??? if AViewInfo.GridView.Site.Components[i] is tbutton then

??? begin

??????? tbutton(AViewInfo.GridView.Site.Components[i]).Tag := -1;

??????? if tbutton(AViewInfo.GridView.Site.Components[i]).Caption =

????????? TcxGridDataCellViewInfo(AViewInfo).DisplayValue then

??????? begin

????????? www := tbutton(AViewInfo.GridView.Site.Components[i]);

??????? end;

????? end;

?

??? end;

??? if TcxGridDataCellViewInfo(AViewInfo).Item.Caption = 'NAME' then

??? begin

????? if www = nil then

????? begin

??????? www := tbutton.Create(AViewInfo.GridView.Site);

??????? www.Visible:=false;

??????? www.Parent := AViewInfo.GridView.Site;

??????? www.Caption := TcxGridDataCellViewInfo(AViewInfo).DisplayValue; //inttostr(iii);

??????? www.Tag := 1;

????? end;

????? www.SetBounds(AViewInfo.ClientBounds.Left, AViewInfo.ClientBounds.Top,

??????? AViewInfo.ClientBounds.Right - AViewInfo.ClientBounds.Left, AViewInfo.ClientBounds.Bottom

????????? -

??????? AViewInfo.ClientBounds.Top);

??????? www.Visible:=true;

??? end;

?? except

?? on e:exception do

?? begin

?? end

?? end;

end;

?

procedure TForm1.cxGrid1DBTableView1TopRecordIndexChanged(Sender: TObject);

var

i,j:integer;

begin

try

? for i := cxgrid1.ActiveView.Site.ComponentCount - 1 downto 0? do

? begin

??? if cxgrid1.ActiveView.Site.Components[i] is tbutton then

??? begin

??????? tbutton(cxgrid1.ActiveView.Site.Components[i]).Tag := -1;

????????????? for j := 0 to TcxGridDBtableView(cxgrid1.ActiveView).ViewInfo.RecordsViewInfo.VisibleCount do

?????????????? begin

????????? if tbutton(cxgrid1.ActiveView.Site.Components[i]).Caption =

??????????? TcxGridDataRowViewInfo(TcxGridDBtableView(cxgrid1.ActiveView).ViewInfo.RecordsViewInfo.Items[j]).CellViewInfos[0].DisplayValue then

??????????? tbutton(cxgrid1.ActiveView.Site.Components[i]).Tag := 1;

??????? end;

??????? if? tbutton(cxgrid1.ActiveView.Site.Components[i]).Tag = -1 then

??????? tbutton(cxgrid1.ActiveView.Site.Components[i]).Free;

??? end;

??? end;

??? except

??? end;

end;

?

procedure TForm1.cxGrid1DBTableView1ColumnSizeChanged(

? Sender: TcxGridTableView; AColumn: TcxGridColumn);

var

i,j:integer;

begin

try

? for i := cxgrid1.ActiveView.Site.ComponentCount - 1 downto 0? do

? begin

??? if cxgrid1.ActiveView.Site.Components[i] is tbutton then

??? begin

??????? tbutton(cxgrid1.ActiveView.Site.Components[i]).Tag := -1;

??????? end;

???? if? tbutton(cxgrid1.ActiveView.Site.Components[i]).Tag = -1 then

??????? tbutton(cxgrid1.ActiveView.Site.Components[i]).Free;

??? end;

??? except

??? end;

end;

?

二,

CXGRID中,只要GetCellHeight事件不為NIL,且optionsview中columnautowidth設為FALSE,即可以實現自動每行行高不同也。

如果要手工用戶拖動而每行行高不同,可用下面代碼

//

procedure TcxGridRowSizingObject.Init(const P: TPoint; AParams: TcxCustomGridHitTest);

var

www:tstringlist;

i,j:integer;

begin

? inherited;

? FRow := TcxCustomGridRow((AParams as TcxGridRowSizingEdgeHitTest).GridRecord);

if?? AParams.ViewInfo? is? tcxgridindicatorrowitemviewinfo?? then

begin

?? www:= tstringlist(tcxgridindicatorrowitemviewinfo(??? AParams.ViewInfo).GridView.Site.Tag);

if (www<>nil) then

begin

? j:=0;

? for i:=0 to www.Count-1 do

? begin

???? if integer(www.Objects[i])=FRow.RecordIndex then

???? begin

???? www[i]:='-1';

???? j:=1;

???? break;

???? end;

? end;

? if j=0 then

? www.AddObject('-1',pointer(FRow.RecordIndex));

? end;

end;

end;

//

procedure TForm1.Button1Click(Sender: TObject);

var

www:tstringlist;

begin

? adotable1.active := true;

? www:=tstringlist.Create;

? cxgrid1.ActiveView.Site.Tag:=integer(pointer(www));

end;

//

procedure TForm1.cxGrid1DBTableView1GetCellHeight(

? Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;

? AItem: TcxCustomGridTableItem;

? ACellViewInfo: TcxGridTableDataCellViewInfo; var AHeight: Integer);

var

www:tstringlist;

i,j:integer;

begin

www:=tstringlist(cxgrid1.activeview.site.tag);

if ((www<>nil) and (www.Count>0)) then

begin

? j:=0;

? for i:=0 to www.Count-1 do

? begin

???? if integer(www.Objects[i])=arecord.RecordIndex then

???? begin

???? j:=strtoint(www[i]);

???? break;

???? end;

? end;

if j<>0 then

begin

?

if j=-1 then

www[i]:=inttostr(cxGrid1DBTableView1.OptionsView.DataRowHeight);

?

j:=strtoint(www[i]);

aheight:=j;

///

?cxGrid1DBTableView1ColumnSizeChanged(nil,nil);

?end;

end;

?

end;

///

procedure TForm1.cxGrid1DBTableView1ColumnSizeChanged(

? Sender: TcxGridTableView; AColumn: TcxGridColumn);

var

i,j:integer;

begin

try

? for i := cxgrid1.ActiveView.Site.ComponentCount - 1 downto 0? do

? begin

??? if cxgrid1.ActiveView.Site.Components[i] is tbutton then

??? begin

??????? tbutton(cxgrid1.ActiveView.Site.Components[i]).Tag := -1;

??????? end;

???? if ?tbutton(cxgrid1.ActiveView.Site.Components[i]).Tag = -1 then

??????? tbutton(cxgrid1.ActiveView.Site.Components[i]).Free;

??? end;

?? except

??? end;

end;

總結

以上是生活随笔為你收集整理的DELPHI的DBGRID有两个难点的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。