使用FocusedView属性得到当前焦点View,用View.DataController得到对应的Data
之后使用Data
-
-
-
-
-
-
示例:
var
…
另外一种方法是使用View.DataController.DataSource.DataSet得到底层数据集后,再用数据集的方法来操作数据。
****************************************************************************
36 激活内置编辑控件
解决:
****************************************************************************
37 隐藏内置编辑控件
解决:
.Controller.EditingController.HideEdit(True);
****************************************************************************
38
移除一个分组列
****************************************************************************
39 保存修改到数据库
解决:
procedure
begin
if
and
end;
****************************************************************************
40 设置内置右键菜单
解决:
内置右键菜单包括二个菜单:cxGridStdHeaderMenu,
- uses
cxGridStdPopupMenu; -
- procedure
TForm1 TComponent; -
AHitTest: TcxCustomGridHitTest; X, Y: Integer; var AllowPopup: Boolean); - begin
-
if ASenderMenu TcxGridStdHeaderMenu -
TcxGridStdHeaderMenu(ASenderMenu).OnPopup := StdHeaderMenuPopup; - end;
-
- procedure
TForm1 TObject); - var
-
I: Integer; - begin
-
with TcxGridStdHeaderMenu(Sender).Items -
for I := Count - -
if Items[I].Caption = By Box' -
begin -
Items[I].Enabled := False; -
System.Break; -
end - end;
****************************************************************************
41
得到选中记录的值
解决:
- 1)
View = False时 -
-
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 = True时 -
Bkm := View.DataController.GetSelectedBookmark(ASelectedRecordIndex); -
if ADataSet -
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禁用内置的右键Footer菜单
解决:
uses
procedure
begin
end;
****************************************************************************
43
主从表任何时候只能展开一个组
解决:
- procedure
TForm1 lapsin( ADataController: TcxCustomDataController; -
-
ARecordIndex:
Integer; var AAllow: Boolean); - var
-
I: Integer; -
C: Integer; - begin
-
AAllow := False; -
C := 0; -
for I := ADataController - -
begin -
if ADataController -
Inc(C); -
if C > -
AAllow := True; -
end; - end;
-
- procedure
TForm1 anding( -
ADataController: TcxCustomDataController; ARecordIndex: Integer; -
var AAllow: Boolean); - begin
-
ADataController.CollapseDetails; - end;
-
- procedure
TForm1 TObject); - begin
cxGrid1DBTableView1 anding; .DataController.OnDetailCollapsing:=ADetailDataControllerColcxGrid1DBTableView1 lapsing; - end;
-
****************************************************************************
- 44
动态创建层次(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 := -
// Creates a View -
View := Grid.CreateView(TcxGridDBTableView) TcxGridDBTableView; -
View.Name := -
// … 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
- procedure
TForm1 mDrawFooterCell( -
Sender: TcxGridTableView; ACanvas: TcxCanvas; -
AViewInfo: TcxGridColumnHeaderViewI nfo; var ADone: Boolean); - var
-
ALevel, ADataGroupIndex: Integer; -
AGridRecord, AGroupRecord: TcxCustomGridRecord; - begin
-
if AViewInfo TcxGridRowFooterCellView Info Row footer -
(TcxGridDBColumn(AViewInfo.Column).DataBinding.FieldName = Area column -
begin -
AGridRecord:= TcxGridRowFooterCellView Info(AViewInfo).GridRecord; -
ALevel:= TcxGridRowFooterCellView Info(AViewInfo).Container.GroupLevel; - ADataGroupIndex:=Sender.DataController.Groups.DataGroupIndexByRowIndex
[AGridRecord .Index]; -
if ADataGroupIndex <> - -
begin -
AGroupRecord := AGridRecord; -
while AGroupRecord <> ALevel -
AGroupRecord := AGroupRecord.ParentRecord; -
AViewInfo.Text := AGroupRecord -
end; -
end; - end;
****************************************************************************
46 访问过滤之后的记录
解决:
var
begin
end;
****************************************************************************
47 获得单元的Font
解决:
cxGrid1DBTableView1.ViewInfo.RecordsViewInfo.Items[1].GetCellViewInfoByItem(
****************************************************************************
48
根据Level名称找到Level对象
解决:
- function
GetLevelByName(AGrid: TcxGrid; ALevelName: TcxGridLevel; -
-
function LoopThroughLevels(ALevel: TcxGridLevel; ALevelName: TcxGridLevel; -
var -
I: Integer; -
begin -
Result := nil; -
for I := ALevel - -
begin -
if ALevel[I].Name = ALevelName -
begin -
Result := ALevel[I]; -
Exit; -
end; -
if ALevel[I].Count > -
begin -
Result := LoopThroughLevels(ALevel[I], ALevelName); -
if Result <> -
Exit; -
end; -
end; -
end; -
- var
-
I: Integer; - begin
-
Result := nil; -
for I := AGrid - -
begin -
if AGrid = ALevelName -
begin -
Result := AGrid.Levels[I]; -
Exit; -
end; -
if AGrid > -
begin -
Result := LoopThroughLevels(AGrid.Levels[I], ALevelName); -
if Result <> -
Exit; -
end; -
end; - end;
****************************************************************************
uses
procedure
begin
end;