delphi控件cxGrid用法大全(6)

来源:网络收集 时间:2025-07-26 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xuecool-com或QQ:370150219 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

procedure TYour_Form.Your_ViewDataControllerSortingChanged(Sender: TObject); begin

TcxCustomDataController(Sender).FocusedRowIndex := 0; end;

**************************************************************************** 53 判断当前行是否第一行或最后一行 解决:

可以使用DataController的IsBOF, IsEOF方法,或者: .Controller.Controller.FocusedRow.IsFirst .Controller.Controller.FocusedRow.IsLast

**************************************************************************** 54 根据指定值查找记录 解决:

DataController提供了好几个方法来得到指定值对应的RecordIndex 对于Bound View可以使用FindRecordIndexByKeyValue方法 **************************************************************************** 55 编辑和显示Blob字段 解决:

该字段的Properties设置为BlobEdit,并将BlobPaintStyle 属性设为 bpsText **************************************************************************** 56 得到可见行数 解决:

.ViewInfo.VisibleRecordCount

**************************************************************************** 57 保存后的行设置为当前行 解决: const

CM_SETFOCUSEDRECORD = WM_USER + 1002; type

TForm1 = class(TForm)

cxGrid1DBTableView1: TcxGridDBTableView; cxGrid1Level1: TcxGridLevel; cxGrid1: TcxGrid;

dxMemData1: TdxMemData; dxMemData1Field1: TStringField; dxMemData1Field2: TIntegerField; DataSource1: TDataSource;

cxGrid1DBTableView1RecId: TcxGridDBColumn; cxGrid1DBTableView1Field1: TcxGridDBColumn; cxGrid1DBTableView1Field2: TcxGridDBColumn; Timer1: TTimer;

CheckBox1: TCheckBox;

procedure Timer1Timer(Sender: TObject);

procedure dxMemData1AfterPost(DataSet: TDataSet); procedure CheckBox1Click(Sender: TObject); private

procedure CMSetFocusedRecord(var Msg: TMessage); message CM_SETFOCUSEDRECORD; public

{ Public declarations } end; var

Form1: TForm1; FocusedIdx: Integer;

implementation

{$R *.dfm}

procedure TForm1.Timer1Timer(Sender: TObject); begin

dxMemData1.AppendRecord(['', IntToStr(Random(1000)), Random(1000)]); end;

procedure TForm1.dxMemData1AfterPost(DataSet: TDataSet); begin

PostMessage(Handle,

CM_SETFOCUSEDRECORD, Integer(cxGrid1DBTableView1), MakeLParam(cxGrid1DBTableView1.Controller.FocusedRowIndex, cxGrid1DBTableView1.Controller.TopRowIndex)); end;

procedure TForm1.CMSetFocusedRecord(var Msg: TMessage); begin

TcxGridDBTableView(msg.WParam).Controller.FocusedRowIndex := Msg.LParamLo; TcxGridDBTableView(msg.WParam).Controller.TopRowIndex := Msg.LParamHi; end;

procedure TForm1.CheckBox1Click(Sender: TObject); begin

Timer1.Enabled := TCheckBox(Sender).Checked; end; end.

**************************************************************************** 58 删除记录并获得焦点

解决:

procedure TForm1.BtnDeleteClick(Sender: TObject); var

FocusedRow, TopRow: Integer; View: TcxGridTableView;

DataController: TcxGridDataController; begin

View := cxGrid1.FocusedView as TcxGridTableView; DataController := View.DataController;

// Remember the top row (the vertical scrollbar position) TopRow := View.Controller.TopRowIndex; // Remember the focused row(!) index FocusedRow := DataController.FocusedRowIndex;

DataController.DeleteFocused;

// After deletion the same row must be focused, // although it will correspond to a different data record DataController.FocusedRowIndex := FocusedRow; // Restore the top row

View.Controller.TopRowIndex := TopRow; end;

**************************************************************************** 59 cxGrid的 TableView 数据排序与对应的数据集同步 解决:

COPYRIGHT BY cnCharles, ALL RIGHTS RESERVED. delphi群: 16497064, blog: http://hi.http://www.njliaohua.com//cnCharles

//描述: cxGrid的 TableView 数据排序与对应的数据集同步, 该方法主要用于打印时 // 的排序与所见到的排序保持一致; //参数: @tv: 排序的cxGridTableView

//说明: @tv: 对应的数据集只支持 ADOQuery与 ClientDataSet;

procedure cxGridSortSyncToDataSet(tv: TcxGridDBTableView); overload; //描述: 功能同上, 实现代码一样, 如果有更改就同步更改

procedure cxGridSortSyncToDataSet(tv: TcxGridDBBandedTableView); overload; procedure cxGridSortSyncToDataSet(tv: TcxGridDBTableView); const

SortArray: array[soAscending..soDescending] of string = (’ASC’, ’DESC’); var

AscFields, DescFields, S, SortOrder: string; IndexPrint: string; I: integer; Index: integer; cds: TClientDataSet;

begin S := ’’; AscFields := ’’; DescFields := ’’;

if tv.SortedItemCount = 0 then Exit;

if tv.DataController.DataSource.DataSet is TADOQuery then begin for I := 0 to tv.SortedItemCount - 1 do begin

SortOrder := SortArray[tv.SortedItems[I].SortOrder]; if S <> ’’ then S := S + ’, ’;

Index := tv.SortedItems[I].Index;

S := S + tv.Columns[Index].DataBinding.Field.FieldName + ’ ’ + SortOrder; end;

(tv.DataController.DataSource.DataSet as TADOQuery).Sort := S;

end else if (tv.DataController.DataSource.DataSet is TClientDataSet) then begin Cds := tv.DataController.DataSource.DataSet as TClientDataSet; for I := 0 to tv.SortedItemCount - 1 do begin Index := tv.SortedItems[I].Index;

S := tv.Columns[Index].DataBinding.Field.FieldName +’;’; AscFields := AscFields + S;

if tv.SortedItems[I].SortOrder = soDescending then DescFields := DescFields + S; end;

if AscFields <> ’’ then

Delete(AscFields, Length(AscFields), 1); //删除 ; if DescFields <> ’’ then

Delete(DescFields, Length(DescFields), 1); IndexPrint := TimeToStr(Now()); Cds.IndexDefs.Clear;

IndexPrint := TimeToStr(Now());

cds.AddIndex(IndexPrint, AscFields, [], DescFields); cds.IndexName := IndexPrint; end; end;

**************************************************************************** 60 cxGRID怎么遍历已经选择的单元格 解决:

n := cxGrid1DBTableView1.DataController.GetSelectedCount;

for i:=0 to n - 1 do begin

Index := cxGrid1DBTableView1.DataController.GetSelectedRowIndex(i); if Index < 0 then continue;

AccID :=

cxGrid1DBTableView1.DataController.GetRowvalue( cxGrid1DBTableView1.DataController.GetRowInfo(Index) ,0);

AccID := dsData.DataSet.FieldByName(’AccountID’).AsString; end;

n := cxGrid1DBTableView1.DataController.GetSelectedCount; for i:=0 to n - 1 do begin

Index := cxGrid1DBTableView1.DataController.GetSelectedRowIndex(i); if Index < 0 then continue;

AccID := cxGrid1DBTableView1.DataController.GetRowvalue( cxGrid1DBTableView1.DataController.GetRowInfo(Index) ,0);//这里的0是列的索引,能指定,也可用通过GridView获取 end;

**************************************************************************** 61 动态设置显示格式 解决:

procedure SetDisplayFormat(ACtrlData: TClientDataSet; TbView: TcxGridDBTableView); var i: integer; begin

if ACtrlData.RecordCount <= 0 then Exit; try

TbView.ClearItems; ACtrlData.First;

for i := 0 to ACtrlData.RecordCount - 1 do begin

if ACtrlData.FieldByName('SQBF_DisplayInGrid').AsString = '1' then //在表格中显示 with TbView.CreateColumn do begin

DataBinding.FieldName := ACtrlData.FieldByName('SQBF_FieldName').AsString; Caption := ACtrlData.FieldByName('SQBF_Caption').AsString; //字段中文标题 Hint := ACtrlData.FieldByName('SQBF_Hint').AsString; Width := ACtrlData.FieldByName('SQBF_Width').AsInteger; HeaderAlignmentHorz := taCenter; end;

ACtrlData.Next; end; except

on E: Exception do

百度搜索“70edu”或“70教育网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,70教育网,提供经典综合文库delphi控件cxGrid用法大全(6)在线全文阅读。

delphi控件cxGrid用法大全(6).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.70edu.com/wenku/460570.html(转载请注明文章来源)
Copyright © 2020-2025 70教育网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:370150219 邮箱:370150219@qq.com
苏ICP备16052595号-17
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:7 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219