欢迎来到冰点文库! | 帮助中心 分享价值,成长自我!
冰点文库
全部分类
  • 临时分类>
  • IT计算机>
  • 经管营销>
  • 医药卫生>
  • 自然科学>
  • 农林牧渔>
  • 人文社科>
  • 工程科技>
  • PPT模板>
  • 求职职场>
  • 解决方案>
  • 总结汇报>
  • ImageVerifierCode 换一换
    首页 冰点文库 > 资源分类 > DOCX文档下载
    分享到微信 分享到微博 分享到QQ空间

    cxGrid技巧汇总一些常用代码.docx

    • 资源ID:3123594       资源大小:20.12KB        全文页数:17页
    • 资源格式: DOCX        下载积分:3金币
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录 QQ登录
    二维码
    微信扫一扫登录
    下载资源需要3金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP,免费下载
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    cxGrid技巧汇总一些常用代码.docx

    1、cxGrid技巧汇总一些常用代码cxGrid技巧汇总=在主从TableView中根据主TableView得到对应的从TableViewvarADetailDC: TcxGridDataController;AView: TcxCustomGridTableView;beginwith cxGrid1DBTableView1.DataController doADetailDC := TcxGridDataController(GetDetailDataController(FocusedRecordIndex, 0);AView := ADetailDC.GridView;end;=定位在第一

    2、行并显示内置编辑器cxDBVerticalGrid1.FocusedRow := cxDBVerticalGrid1.Rows0;cxDBVerticalGrid1.ShowEdit;=隐藏 字符串该文本存储在scxGridNoDataInfoText资源字符串,可以将该资源字符串的内容设为空来隐藏该文本。uses cxClasses, cxGridStrs;.cxSetResourceString(scxGridNoDataInfoText, );/如果 字符串已经显示,需要调用:.LayoutChanged;=删除应用过滤后的行varI: Integer;beginwith dofor I

    3、 := 0 to ViewData.RecordCount - 1 dobeginViewData.Records0.Focused := True;DataController.DataSet.Delete;end;=根据单元的值设置样式procedure .StylesGetContentStyle(Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);beginif ARecord.ValuesAItem.Index

    4、 = aSomeValue thenAStyle := ;end;procedure .StylesGetContentStyle(Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);varAColumn: TcxCustomGridTableItem;beginAColumn := (Sender as TcxGridDBTableView).GetColumnByFieldName(Email);if VarToSt

    5、r(ARecord.ValuesAColumn.Index) = thenAStyle := cxStyleNullEmail;end;=TcxCustomGridTableView.FindItemByName, TcxGridDBTableView.GetColumnByFieldName orTcxGridDBDataController.GetItemByFieldNamewith cxGrid1DBBandedTableView1.DataController doAValue := ValuesFocusedRecordIndex, GetItemByFieldName(SomeF

    6、ieldName).Index;=动态生成BandedViewvarAView: TcxCustomGridView;beginAView := .CreateView(TcxGridDBBandedTableView);TcxGridDBBandedTableView(AView).DataController.DataSource := ;TcxGridDBBandedTableView(AView).Bands.Add;with TcxGridDBBandedTableView(AView).Bands.Add dobeginVisible := False;FixedKind := f

    7、kLeft;end;TcxGridDBBandedTableView(AView).DataController.CreateAllItems;.GridView := AView;=当底层数据集为空时显示一条空记录procedure .Enter(Sender: TObject);varView: TcxGridDBTableView;beginView := TcxGridDBTableView(Sender as TcxGrid).FocusedView);if View.DataController.DataSet.IsEmpty thenbeginView.DataControlle

    8、r.DataSet.Append;View.Controller.EditingController.ShowEdit;end;end;=在当前View插入记录使用FocusedView属性得到当前焦点View,用View.DataController得到对应的Data Controller,之后使用Data Controller的方法来操作数据:- Append- Insert- Post- Cancel- DeleteFocused- DeleteSelection示例:varARecIndex: Integer;View.DataController.Append;ARecIndex :

    9、= View.DataController.FocusedRecordIndex;View.DataController.ValuesARecIndex, SomeItemIndex := SomeValue;View.DataController.Post;另外一种方法是使用View.DataController.DataSource.DataSet得到底层数据集后,再用数据集的方法来操作数据。=激活内置编辑控件1) .Controller.EditingController.ShowEdit();2) .Controller.EditingController.StartEditShowi

    10、ngTimer();3) .Controller.EditingItem := ;4) .Editing := True;隐藏内置编辑控件.Controller.EditingController.HideEdit(True);=移除一个分组列.GroupIndex := -1;.Visible := True;=保存修改到数据库procedure .FormClose(Sender: TObject; var Action: TCloseAction);beginif (.FocusedView nil) and (.FocusedView.DataController.EditState

    11、) then.FocusedView.DataController.Post;end;=设置内置右键菜单内置右键菜单包括二个菜单:cxGridStdHeaderMenu, TcxGridStdFooterMenuuses cxGridStdPopupMenu;procedure TForm1.cxGridPopupMenu1Popup(ASenderMenu: TComponent;AHitTest: TcxCustomGridHitTest; X, Y: Integer; var AllowPopup: Boolean);beginif ASenderMenu is TcxGridStdHe

    12、aderMenu thenTcxGridStdHeaderMenu(ASenderMenu).OnPopup := StdHeaderMenuPopup;end;procedure TForm1.StdHeaderMenuPopup(Sender: TObject);varI: Integer;beginwith TcxGridStdHeaderMenu(Sender).Items dofor I := 0 to Count - 1 doif ItemsI.Caption = Group By Box thenbeginItemsI.Enabled := False;System.Break;

    13、endend;=得到选中记录的值1) View.DataController.DataModeController.GridMode = False时RecIdx := View.Controller.SelectedRecordsi.RecordIndex;ColIdx := View.DataController.GetItemByFieldName(AFieldName).Index;OutputVal := View.DataController.ValuesRecIdx, ColIdx;/RecID := View.DataController.GetRecordId(RecIdx)

    14、;/OutputVal := ADataSet.Lookup(View.DataController.KeyFieldNames, RecID, AFieldName);2) View.DataController.DataModeController.GridMode = True时Bkm := View.DataController.GetSelectedBookmark(ASelectedRecordIndex);if ADataSet.BookmarkValid(TBookmark(Bkm) thenbeginADataSet.Bookmark := TBookmark(Bkm);Ou

    15、tputVal := ADataSet.FieldByName(AFieldName).Value;end;View.BeginUpdate;View.DataController.BeginLocate;try/ make changes herefinallyView.DataController.EndLocate;View.EndUpdate;end;=在GridMode禁用内置的右键Footer菜单uses cxGridStdPopupMenu;procedure cxGridPopupMenuOnPopup(.)beginif (ASenderMenu is TcxGridStdF

    16、ooterMenu) and.DataController.DataModeController.GridMode thenAllowPopup := False;end;=主从表任何时候只能展开一个组procedure TForm1.ADetailDataControllerCollapsing(ADataController: TcxCustomDataController; ARecordIndex: Integer;var AAllow: Boolean);varI: Integer;C: Integer;beginAAllow := False;C := 0;for I := 0 t

    17、o ADataController.RecordCount - 1 dobeginif ADataController.GetDetailExpanding(I) thenInc(C);if C 1 thenAAllow := True;end;end;procedure TForm1.ADetailDataControllerExpanding(ADataController: TcxCustomDataController; ARecordIndex: Integer;var AAllow: Boolean);beginADataController.CollapseDetails;end

    18、;procedure TForm1.FormCreate(Sender: TObject);begincxGrid1DBTableView1.DataController.OnDetailExpanding := ADetailDataControllerExpanding;cxGrid1DBTableView1.DataController.OnDetailCollapsing := ADetailDataControllerCollapsing;end;=动态创建层次(Level)和视图(View)varGrid: TcxGrid;Level: TcxGridLevel;View: Tcx

    19、GridDBTableView;begin/ Creates a Grid instanceGrid := TcxGrid.Create(SomeOwner);Grid.Parent := SomeParent;/ Creates a LevelLevel := Grid.Levels.Add;Level.Name := SomeLevelName;/ Creates a ViewView := Grid.CreateView(TcxGridDBTableView) as TcxGridDBTableView;View.Name := SomeViewName;/ and binds it t

    20、o the LevelLevel.GridView := View;/ Hooks up the View to the dataView.DataController.DataSource := SomeDataSource;/ and creates all columnsView.DataController.CreateAllItems;end;=获得Group Footer合计行对应的记录procedure TForm1.cxGrid1DBTableView1CustomDrawFooterCell(Sender: TcxGridTableView; ACanvas: TcxCanv

    21、as;AViewInfo: TcxGridColumnHeaderViewInfo; var ADone: Boolean);varALevel, ADataGroupIndex: Integer;AGridRecord, AGroupRecord: TcxCustomGridRecord;beginif AViewInfo is TcxGridRowFooterCellViewInfo and / Row footer(TcxGridDBColumn(AViewInfo.Column).DataBinding.FieldName = Area) then / Area columnbegin

    22、AGridRecord := TcxGridRowFooterCellViewInfo(AViewInfo).GridRecord;ALevel := TcxGridRowFooterCellViewInfo(AViewInfo).Container.GroupLevel;ADataGroupIndex := Sender.DataController.Groups.DataGroupIndexByRowIndexAGridRecord.Index;if ADataGroupIndex -1 thenbeginAGroupRecord := AGridRecord;while AGroupRe

    23、cord.Level ALevel doAGroupRecord := AGroupRecord.ParentRecord;AViewInfo.Text := AGroupRecord.DisplayTexts0;end;end;end;=访问过滤之后的记录varI: Integer;beginMemo1.Lines.Clear;with cxGrid1DBTableView1.DataController dofor I := 0 to FilteredRecordCount - 1 doMemo1.Lines.Add(DisplayTextsFilteredRecordIndexI, 0)

    24、;end;=获得单元的FontcxGrid1DBTableView1.ViewInfo.RecordsViewInfo.Items1.GetCellViewInfoByItem(cxGrid1DBTableView1Company).EditViewInfo.Font;=根据Level名称找到Level对象function GetLevelByName(AGrid: TcxGrid; ALevelName: string): TcxGridLevel;function LoopThroughLevels(ALevel: TcxGridLevel; ALevelName: string): Tc

    25、xGridLevel;varI: Integer;beginResult := nil;for I := 0 to ALevel.Count - 1 dobeginif ALevelI.Name = ALevelName thenbeginResult := ALevelI;Exit;end;if ALevelI.Count 0 thenbeginResult := LoopThroughLevels(ALevelI, ALevelName);if Result nil thenExit;end;end;end;varI: Integer;beginResult := nil;for I := 0 to AGrid.Levels.Count - 1 dobeginif AGrid.LevelsI.Name = ALevelName thenbeginResult := AGrid.LevelsI;Exit;end;if AGrid.LevelsI.Count 0 thenbeginResult := LoopThroughLevels(AGrid.LevelsI, ALevelName);if Result nil the


    注意事项

    本文(cxGrid技巧汇总一些常用代码.docx)为本站会员主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

    copyright@ 2008-2023 冰点文库 网站版权所有

    经营许可证编号:鄂ICP备19020893号-2


    收起
    展开