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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Delphi CxGrid 汇总(3)

發(fā)布時(shí)間:2025/6/17 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Delphi CxGrid 汇总(3) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

列??
解決:
????? <aColumn>.GroupIndex?? :=?? -1;??
????? <aColumn>.Visible?? :=?? True;
****************************************************************************
39 保存修改到數(shù)據(jù)庫(kù)
解決:
procedure?? <aForm>.FormClose(Sender:?? TObject;?? var?? Action:?? TCloseAction);??
begin??
if?? (<aGrid>.FocusedView <> nil)
and?? (<aGrid>.FocusedView.DataController.EditState <> []) then??
????????? <aGrid>.FocusedView.DataController.Post;??
end;
****************************************************************************
40 設(shè)置內(nèi)置右鍵菜單
解決:
內(nèi)置右鍵菜單包括二個(gè)菜單:cxGridStdHeaderMenu,?? TcxGridStdFooterMenu??

[delphi]?view plaincopy
  • uses???cxGridStdPopupMenu;????
  • ?????
  • procedure???TForm1.cxGridPopupMenu1Popup(ASenderMenu:???TComponent;????
  • ??????AHitTest:???TcxCustomGridHitTest;???X,???Y:???Integer;???var???AllowPopup:???Boolean);????
  • begin????
  • ??????if???ASenderMenu???is???TcxGridStdHeaderMenu???then????
  • ??????????TcxGridStdHeaderMenu(ASenderMenu).OnPopup???:=???StdHeaderMenuPopup;????
  • end;????
  • ?????
  • procedure???TForm1.StdHeaderMenuPopup(Sender:???TObject);????
  • var????
  • ??????I:???Integer;????
  • begin????
  • ??????with???TcxGridStdHeaderMenu(Sender).Items???do????
  • ??????????for???I???:=???0???to???Count???-???1???do????
  • ??????????????if???Items[I].Caption???=???'Group???By???Box'???then????
  • ??????????????begin????
  • ??????????????????Items[I].Enabled???:=???False;????
  • ??????????????????System.Break;????
  • ??????????????end????
  • end;??
  • ****************************************************************************
    41 得到選中記錄的值
    解決:

    [delphi]?view plaincopy
  • 1)???View.DataController.DataModeController.GridMode???=???False時(shí)????
  • ?????
  • ??????RecIdx???:=???View.Controller.SelectedRecords[i].RecordIndex;????
  • ??????ColIdx???:=???View.DataController.GetItemByFieldName(AFieldName).Index;????
  • ??????OutputVal???:=???View.DataController.Values[RecIdx,???ColIdx];????
  • ?????
  • ??????//RecID???:=???View.DataController.GetRecordId(RecIdx);????
  • ??????//OutputVal???:=???ADataSet.Lookup(View.DataController.KeyFieldNames,???RecID,???AFieldName);????
  • ?????
  • 2)???View.DataController.DataModeController.GridMode???=???True時(shí)????
  • ??????Bkm???:=???View.DataController.GetSelectedBookmark(ASelectedRecordIndex);????
  • ??????if???ADataSet.BookmarkValid(TBookmark(Bkm))???then????
  • ??????begin????
  • ??????????ADataSet.Bookmark???:=???TBookmark(Bkm);????
  • ??????????OutputVal???:=???ADataSet.FieldByName(AFieldName).Value;????
  • ??????end;????
  • ?????
  • ??????View.BeginUpdate;????
  • ??????View.DataController.BeginLocate;????
  • ??????try????
  • ??????????//???make???changes???here…????
  • ??????finally????
  • ??????????View.DataController.EndLocate;????
  • ??????????View.EndUpdate;????
  • ??????end;??
  • ****************************************************************************
    42 在GridMode禁用內(nèi)置的右鍵Footer菜單
    解決:
    uses?? cxGridStdPopupMenu;??
    ???
    procedure?? cxGridPopupMenuOnPopup(...)??
    begin??
    ????? if?? (ASenderMenu?? is?? TcxGridStdFooterMenu)?? and??
    ????????????? <GridView>.DataController.DataModeController.GridMode?? then??
    ????????? AllowPopup?? :=?? False;??
    end;
    ****************************************************************************
    43 主從表任何時(shí)候只能展開一個(gè)組
    解決:

    [delphi]?view plaincopy
  • procedure???TForm1.ADetailDataControllerCollapsin(??ADataController:??TcxCustomDataController;????
  • ??
  • ARecordIndex:???Integer;??var???AAllow:???Boolean);????
  • var????
  • ??????I:???Integer;????
  • ??????C:???Integer;????
  • begin????
  • ??????AAllow???:=???False;????
  • ??????C???:=???0;????
  • ??????for???I???:=???0???to???ADataController.RecordCount???-???1???do????
  • ??????begin????
  • ??????????if???ADataController.GetDetailExpanding(I)???then????
  • ??????????????Inc(C);????
  • ??????????if???C???>???1???then????
  • ??????????????AAllow???:=???True;????
  • ????????end;????
  • end;????
  • ?????
  • procedure???TForm1.ADetailDataControllerExpanding(????
  • ??????ADataController:???TcxCustomDataController;???ARecordIndex:???Integer;????
  • ??????var???AAllow:???Boolean);????
  • begin????
  • ??????ADataController.CollapseDetails;????
  • end;????
  • ?????
  • procedure???TForm1.FormCreate(Sender:???TObject);????
  • begin????????cxGrid1DBTableView1.DataController.OnDetailExpanding:=ADetailDataControllerExpanding;?????????cxGrid1DBTableView1.DataController.OnDetailCollapsing:=ADetailDataControllerCollapsing;????
  • end;??
  • ****************************************************************************??
  • 44?動(dòng)態(tài)創(chuàng)建層次(Level)和視圖(View)??
  • 解決:??
  • var????????
  • ??????Grid:???TcxGrid;????????
  • ??????Level:???TcxGridLevel;????????
  • ??????View:???TcxGridDBTableView;????????
  • begin????
  • ??????//???Creates???a???Grid???instance????
  • ??????Grid???:=???TcxGrid.Create(SomeOwner);????????
  • ??????Grid.Parent???:=???SomeParent;????????
  • ??????//???Creates???a???Level????
  • ??????Level???:=???Grid.Levels.Add;????????
  • ??????Level.Name???:=???'SomeLevelName';????
  • ??????//???Creates???a???View????
  • ??????View???:=???Grid.CreateView(TcxGridDBTableView)???as???TcxGridDBTableView;????????
  • ??????View.Name???:=???'SomeViewName';????
  • ??????//???…???and???binds???it???to???the???Level????
  • ??????Level.GridView???:=???View;????????
  • ??????//???Hooks???up???the???View???to???the???data????
  • ??????View.DataController.DataSource???:=???SomeDataSource;????????
  • ??????//???…???and???creates???all???columns????
  • ??????View.DataController.CreateAllItems;????????
  • end;??
  • ****************************************************************************
    45 獲得Group?? Footer合計(jì)行對(duì)應(yīng)的記錄
    解決:

    [delphi]?view plaincopy
  • procedure???TForm1.cxGrid1DBTableView1CustomDrawFooterCell(????
  • ??????Sender:???TcxGridTableView;???ACanvas:???TcxCanvas;????
  • ??????AViewInfo:???TcxGridColumnHeaderViewInfo;???var???ADone:???Boolean);????
  • var????
  • ??????ALevel,???ADataGroupIndex:???Integer;????
  • ??????AGridRecord,???AGroupRecord:???TcxCustomGridRecord;????
  • begin????
  • ??????if???AViewInfo???is???TcxGridRowFooterCellViewInfo???and????//???Row???footer????
  • ????????????(TcxGridDBColumn(AViewInfo.Column).DataBinding.FieldName???=???'Area')???then?????//???Area???column????
  • ???begin????
  • ????????AGridRecord:=???TcxGridRowFooterCellViewInfo(AViewInfo).GridRecord;????
  • ????????ALevel:=?TcxGridRowFooterCellViewInfo(AViewInfo).Container.GroupLevel;????
  • ADataGroupIndex:=Sender.DataController.Groups.DataGroupIndexByRowIndex[AGridRecord.Index];????
  • ?????????if???ADataGroupIndex???<>???-1???then????
  • ?????????begin????
  • ????????????AGroupRecord???:=???AGridRecord;????
  • ????????????while???AGroupRecord.Level???<>???ALevel???do????
  • ????????????AGroupRecord???:=???AGroupRecord.ParentRecord;????
  • ????????????AViewInfo.Text???:=???AGroupRecord.DisplayTexts[0];????
  • ?????????end;????
  • ?????end;????
  • end;??
  • ****************************************************************************
    46 訪問過濾之后的記錄
    解決:
    var??
    ????? I:?? Integer;??
    begin??
    ????? Memo1.Lines.Clear;??
    ????? with?? cxGrid1DBTableView1.DataController?? do??
    ????????? for?? I?? :=?? 0?? to?? FilteredRecordCount?? -?? 1?? do??
    ????????????? Memo1.Lines.Add(DisplayTexts[FilteredRecordIndex[I],?? 0]);??
    end;

    ****************************************************************************
    47 獲得單元的Font
    解決:
    cxGrid1DBTableView1.ViewInfo.RecordsViewInfo.Items[1].GetCellViewInfoByItem(??
    ????? cxGrid1DBTableView1Company).EditViewInfo.Font;
    ****************************************************************************
    48 根據(jù)Level名稱找到Level對(duì)象
    解決:

    [delphi]?view plaincopy
  • function???GetLevelByName(AGrid:???TcxGrid;???ALevelName:???string):???TcxGridLevel;????
  • ?????
  • ??????function???LoopThroughLevels(ALevel:???TcxGridLevel;???ALevelName:???string):???TcxGridLevel;????
  • ??????var????
  • ??????????I:???Integer;????
  • ??????begin????
  • ??????????Result???:=???nil;????
  • ??????????for???I???:=???0???to???ALevel.Count???-???1???do????
  • ??????????begin????
  • ??????????????if???ALevel[I].Name???=???ALevelName???then????
  • ??????????????begin????
  • ??????????????????Result???:=???ALevel[I];????
  • ??????????????????Exit;????
  • ??????????????end;????
  • ??????????????if???ALevel[I].Count???>???0???then????
  • ??????????????begin????
  • ??????????????????Result???:=???LoopThroughLevels(ALevel[I],???ALevelName);????
  • ??????????????????if???Result???<>???nil???then????
  • ??????????????????????Exit;????
  • ??????????????end;????
  • ??????????end;????
  • ??????end;????
  • ?????
  • var????
  • ??????I:???Integer;????
  • begin????
  • ??????Result???:=???nil;????
  • ??????for???I???:=???0???to???AGrid.Levels.Count???-???1???do????
  • ??????begin????
  • ??????????if???AGrid.Levels[I].Name???=???ALevelName???then????
  • ??????????begin????
  • ??????????????Result???:=???AGrid.Levels[I];????
  • ??????????????Exit;????
  • ??????????end;????
  • ??????????if???AGrid.Levels[I].Count???>???0???then????
  • ??????????begin????
  • ??????????????Result???:=???LoopThroughLevels(AGrid.Levels[I],???ALevelName);????
  • ??????????????if???Result???<>???nil???then????
  • ??????????????????Exit;????
  • ??????????end;????
  • ??????end;????
  • end;??
  • ****************************************************************************

    ?49 指定Filter?? Builder打開/保存過濾文件的默認(rèn)路徑
    解決:
    uses??
    ????? ...,?? cxFilterControlDialog;??
    ???
    procedure?? TForm.GridView1FilterControlDialogShow(??
    ????? Sender:?? TObject);??
    begin??
    ????? TfmFilterControlDialog(Sender).OpenDialog.InitialDir?? :=?? 'D:/'??
    end;

    轉(zhuǎn)載于:https://www.cnblogs.com/jupt/p/3922932.html

    《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

    總結(jié)

    以上是生活随笔為你收集整理的Delphi CxGrid 汇总(3)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。