1. 程式人生 > 其它 >cxgrid屬性說明,每次用的時候費時費力查詢。

cxgrid屬性說明,每次用的時候費時費力查詢。

由層得到資料表名:

procedure TFB_PatientWaiting.cxgrdbtblvwGrid1DBTableView_MyPatienWaitingDblClick(
  Sender: TObject);
var tmp_ifGHD : Boolean;
MyTV: TcxGridDBTableView;
begin
  tmp_ifGHD := False;
  if cxgrd_Patient.ActiveLevel.Index = 0 then  tmp_ifGHD := True;
  MyTV := TcxGridDBTableView(cxgrd_Patient.ActiveLevel.GridView);
  currentPatientSelect(tmp_ifGHD,(MyTV.DataController.DataSource.DataSet as TClientDataSet));
end;

當前記錄的top值:
cxgrid.Controller.FocusedRow.ViewInfo.Bounds.Top
------------------------------------------------------
用程式碼進行過濾是提示轉換bool異常錯誤:

用程式碼cxgrid使用過濾時,使用like等表示式,欄位型別必須是string型別,不能其他如integer。否則做like時轉換會出現異常。被這個破問題搞暈了;
------------------------------------------------------

cxgrid有幾個level,如何知道當前那一層active:

當前啟用的是cxgrd_JY.ActiveLevel.Index;

轉 cxgrid屬性說明

TCXGRID控制元件:
屬性:
ActiveLevel: 當前層
BorderStyle: 視窗風格
Color: 顏色
FocusedView: 當前View;
Font: 字型
LevelTabs: 類似PageControls頭設定
CaptionAlgnment:標題對齊方式
Images:圖示
Style:風格
Levels:
RootLevelOptions:層選項
DetailTabsPosition: 類似PageControls頭顯示位置;
TabsForEmptyDetails: 如果資料為空是否顯示Tabs


TcxGridLevel元件:
屬性:
Active: 讀寫啟用該層;
Controls: 讀寫指向TCXGrid;


CanBeVisible: 讀取是否能設定可見;
Count: 讀取子層個數;
Displaycaption: 讀取層標題;
IsMaster: 讀取是否cxgrid的最上層;
Items: 讀取層組,例: Items[0]訪問第一個層;
Level: 讀取層級數;
VisibleCount: 讀取可見層個數
VisibleIndex: 讀取可見索引個數
VisibleItems: 讀取可見層組,例:VisibleItems[0]訪問第一個可見層
Caption: 讀寫層標題;
GridView: 指定或讀取該層的Grid顯示;
ImageIndex: 讀寫圖示索引
Options: TcxGridLevelOptions選項
DetailFrameColor: 讀或寫明細表格顏色
DetailFramWidth: 讀或寫明細表格
DetailTabsPosition: 讀或寫Tab位置,類似PageControlsTabs
Styles: 樣式
Tab: 讀或設定tab樣式
tabsBackground: 讀或設定tab背景樣式
Visible: 讀或設定是否可見
方法:
Add: 增加一個Level;
Levels[i].Add:增加一個子Level;
TcxGridDBBandedTableView元件:
屬性:
BackGroundBitmaps:背景圖片選項
Background:背景圖
Bandbackground:帶背景圖
Bankheader:帶頭背景
Content:細節區背景
filterBox:過濾區背景
footer:註腳背景
group: 組背景
header:列頭背景
preview:預覽區背景
Bands:帶列表
DataController: 資料控制
DataSource:資料來源
DetailKeyFieldNames:主從表時設定細表鍵欄位名
KeyFieldNames: 主從表時設定關鍵欄位名
MasterKeyFieldNames:主從表時設定主表鍵欄位名
Summary:合計組
FooterSummaryItems:註腳定義
FooterSummaryItems:組腳定義
FilterBox:過濾框
CustomizeDialog:是否自定義過濾條件
Position:過濾框顯示位置
Visible:顯示過濾框
NavigatorButtons:導航條設定
Append:增加按鈕設定
Enabled:是否禁用該按鈕
Visible:是否顯示該按鈕
ImageIndex:圖示ID
Cancel:取消按鈕設定,具體設定同Append;
ConfirmDelete:刪除時是否確認提示
Delete: 具體設定同Append;
Edit: 具體設定同Append;
First: 具體設定同Append;
Insert: 具體設定同Append;
Last: 具體設定同Append;
Next: 具體設定同Append;
Filter: 具體設定同Append;
GotoBookmark: 具體設定同Append;
NextPage: 具體設定同Append;
Post: 具體設定同Append;
Prior: 具體設定同Append;
PriorPage: 具體設定同Append;
Refresh: 具體設定同Append;
SaveBookmark: 具體設定同Append;
OptionsBehavior:行為選項
AlwaysShowEditor:是否總是顯示編輯條
BandHeaderHints:帶頭是否顯示提示
CellHints:單元格是否顯示提示
ColumnHeaderHints:列頭是否顯示提示
CopyCaptionsToClipboard:是否允許複製標題到剪貼簿
CopyPreviewToClipboard:是否允許複製預覽內容到剪貼簿
ExpandMasterRowOnDblClik:是否允許雙擊行顯示明細
FocusFirstCellOnNewRecord:新增記錄時是否焦點指向第一列單元格
GoToNextCellOnEnter:按回車是否自動跳到下一單元格
NavigatorHints:是否顯示導航條提示
OptionsCustomize:自定義選項
BandHiding:是否顯示帶
BandMoving:是否允許拖動帶
ColumnFiltering:是否允許列過濾
ColumnGrouping:是否允許列分組
ColumnHiding:列頭是否隱藏
ColumnHorzSizing:是否允許調整列寬度
ColumnMoving:是否允許列拖動
ColumnSorting:是否允許列排序
ColumnVertSizing:是否允許調整列高度
DataRowSizing:是否允許調整資料行高度
GroupBySorting:是否允許組排序
GroupRowSizing:是否允許調整組行高度
OptionData: 允許資料操作
Appending: 是否允許增加
CancelOnExit: 退出時是否自動取消修改
Deleting: 是否允許刪除
DeletingConfirmation: 刪除是否提示
Editing :是否允許編輯
Inserting: 是否允許插入
OptionsSelection: 單元格操作
CellMultiSelect:是否允許選擇多單元格
CellSelect: 進入單元格是否選擇
InvertSelect: 是否允許轉換選擇
MultiSelect: 是否允許多行選擇
HideFocusRectOnExit: 移開是否隱藏焦點
UnselectFocusedRecordOnExit:移開是否允許取消焦點
OptionsView:表格選項
BandCaptionsInColumnAlternateCaption:是否允許在列裡修改帶標題
BandHeaderHeight: 帶頭高度
BandHeaderLineCount: 帶頭顯示行數
BandHeaders: 是否顯示帶頭
CellAutoHeight:單元格是否自動高度
CellTextMaxLineCount: 單元格文字最大行數
ColumnAutoWidth: 列是否自動寬度
DataRowHeight: 資料行高度
Footer:是否允許顯示註腳
FooterAutoHeight: 註腳是否自動適應高度
FooterMultiSummaries:是否允許多註腳
GridLineColor:表格行線顏色
GridLines:顯示錶格行線型別
GroupByBox:是否允許拖動列到分組區進行分組
GroupFooters:顯示組腳型別
Header:是否顯示列頭
HeaderAutoHeight:列頭是否自動適應高度
HeaderHeight: 列頭高度
IndicatorWidth:是否顯示左邊指示條
IndicatorWidth: 指示條寬度
Navigator: 是否顯示導航條
NavigatorOffSet: 導航條偏移位置
ShowColumnFilterButtons: 是否顯示列過濾按鈕
ShowEditButtons: 是否顯示編輯按鈕
Preview:預覽選項
AutoHeight:是否自動適應高度
Column:要預覽的列,只能選一列
LeftIndent: 左縮排點數
MaxLineCount:最大顯示行數
RightIndent:右縮排點數
Visible: 預覽是否可見
PopupMenu:彈出選單
Styles:樣式或風格組
BackGround:背景風格
Content:明細風格
Footer:註腳風格
Group:組風格
GroupSummary:組合計區風格
Header:頭風格
Indicator:指示區風格
Preview:預覽區風格
Selection:選擇區風格
StyleSheet:風格組,選中後自動設定各區風格
方法或函式:
CreateColumn:
引數:無;
功能:新建一列;
返回:返回列型別結果;
GetColumnByFieldName:
引數:欄位名串;
功能:取得指定欄位列;
返回:返回列型別結果;
例:MyTV.GetColumnByFieldName('First').Visible := False;
CleaarItems:
引數:無;
功能:清除全部顯示列;
返回:無
CreateItem:
引數:無;
功能:建一顯示列;
返回:列型別值
StoreToIniFile:匯出佈局到Ini檔案
StoreToRegistry:匯出佈局到登錄檔
StoreToStream:匯出佈局到流體
RestoreFromIniFile: 從Ini檔案恢復佈局
RestoreFromRegistry:從登錄檔恢復佈局
RestoreFromStream:從流體恢復佈局
FindItemByID:根據ID號查詢列
FindItemByName:根據列名查詢列
FindItemByTag:根據Tag查詢列
IndexofItem:返回列的序號
CreateViewInfo:建表格
TCXGRID用法指南
假設已設定以下變數
MycxGrid: TcxGrid;
MycxGridLevel: TcxGridLevel;
MyTV: TcxGridDBTableView;
MyDataSource: TDataSource;
方法:
一、 建層和層檢視
MycxGrid := TcxGrid.Create(self);
MycxGridLevel := MycxGrid.Levels.Add; //建層
MyTV:= TcxGridDBTableView(MycxGrid.createview(TcxGridDBTableView));//建檢視
MycxGridLevel.Control := MycxGrid;//指定關係
MycxGridLevel.GridView := MyTV;//指定檢視
TcxGridDataController(GetDetailDataController(FocusedRecordIndex, 0)).GridView;//得到下層檢視
二、設定表格位置和大小
MycxGrid.ParentWindow := self.Handle;
MycxGrid.Top := 0;
MycxGrid.Height := 200;
MycxGrid.Width := 400;
MyTV.Preview.visible := true;
三、 設定資料來源及分配全部欄位
MyTV.DataController.DataSource := MyDataSource;
MyTV.DataController.DeleteAllItems; //清除全部欄位
MyTV.DataController.CreateAllItems; //建全部顯示欄位
四、 動態增加顯示列及列訪問
var
iIndex: integer;
vCol: TcxGridDBColumn;
vImgCom: TcxImageComboBoxItem;
i,j: integer;
for i:= 0 to Mydatasource.dataset.FieldCount -1 do
begin
vCol := MyTV.CreateColumn;
vCol.DataBinding.FieldName:=Mydatasource.dataset.Fields[i].FieldName;
if (i = 1) then
begin
vCol.PropertiesClassName := 'TcxImageComboBoxProperties'; ////分割槽分大小寫
vCol.DataBinding.ValueType := 'String';
for j := 0 to 5 do
begin
vImgCom:=TcxImageComboBoxProperties(vCol.Properties).Items.Add;
vImgCom.Description := IntToStr(j);
vImgCom.Value := IntToStr(j);
end;
end;
end;
showmessage(MyTV.Columns[0].Caption);//列標題訪問
showmessage(MyTV.Columns[0].DataBinding.FieldName);//列欄位名訪問
MyTV.Columns[0].SortIndex := 0;
MyTV.Columns[0].SortOrder := soAscending; //列升序排序
MyTV.Columns[0].SortIndex := -1;
MyTV.Columns[0].SortOrder := soNone; //取消列排序
MyTV.DataController.Search.Locate(MyTV.GetColumnByFieldName(FieldName).Index, 查詢值);// 列值搜尋
MyTV.DataController.FocusedRowIndex := MyTV.DataController.FocusedRowIndex - 1;//記錄回翻,即Prior;
DBView.DataController.FocusedRowIndex := DBView.DataController.FocusedRowIndex + 1; //記錄後翻,即Next;
Aa:=MyTV.datacontroller.values[1,1] ;// 訪問第二行第二列的值
MyTV.Columns[0].DataBinding.ValueTypeClass := TcxStringValueType;//設定列欄位型別,
其他如整型[TcxIntegerValueType],浮點型[TcxFloatValueType];


//設定列風格:
MyFirstColumnStyle := TcxStyle.Create(Self);
MyFirstColumnStyle.Color := clAqua;
MyFirstColumnStyle.TextColor := clBlue;
MyTV.Columns[1].Styles.Content := MyFirstColumnStyle;


//設定列下拉框選擇列表及型別
var
A:TDataSource:
B:TcxlookupcomboboxProperties;
begin
A:=TDataSource.create(self);
B:=tcxlookupcomboboxproperties.create(self);
A.Dataset:=Dic_ry_xb;//此處指定資料來源。
B.listdource:=A;//此處指明欄位的listsource屬性。
B.keyfieldnames:='a'; //此處指明欄位的關鍵欄位
B.listfieldnames:='b'; //此處指明欄位的返回值。
B.listcolumns.items[0].caption:='x’; //此處預設是會建立一個欄位,但是顯示的表頭是name,所以此處讓它顯示為自己想要的中午顯示。
MYTVc1_sex_code.Properties:=B; //此處指明是那個欄位。
end;


五、 設定列外觀
MyTV.OptionsView.ColumnAutoWidth := true //列自動寬度
MyTV.OptionsView.CellAutoHeight := true //單元自動高度
MyTV.OptionsView.Footer := true //表格合計行顯示
MyTV.OptionsView.Header := true // 表格頭顯示
MyTV.OptionsView.Indicator := true //顯示指示條
MyTV.OptionsView.GroupByBox:=true //顯示分組框
MyTV.Preview := True //顯示預覽區


六、 設定表格樣式
var MyStyleSheet:TcxGridTableViewStyleSheet;
MyStyle :TcxStyle;
begin
MyStyleSheet := TcxGridTableViewStyleSheet.Create();
MyStyle := TcxStyle.Create(self);
MyStyle.Color := clBlack;
MyStyle.TextColor := clWrite;
MyTV.Styles.Background := MyStyle; //設定背景樣式
MyStyleSheet.AddStyles(MyStyle);//分配樣式
cxStyleRepository.CreateStyleSheet(MyStyleSheet);
MyTV.Styles.StyleSheet := cxStyleRepository; //分配樣式
End;
七、 設定Preview列
前提條件是設定footer=true;
MyTV.Preview.column := MyTVField1;//設定預覽列
MyTV.Preview.MaxLineCount := 4;//設定預覽列最大顯示行數
MyTV.Preview.LeftIndent :=150; //顯示左縮排
MyTV.Preview.RightIndent :=150;//顯示右縮排
八、 Footer設定
Var ASummary: TcxDataSummary;
MyFooterItems :TcxDataFooterSummaryItems;
Acolumn :TcxGridDBColumn;
ASummary := MyTV.DataController.Summary; //提取Footer;
MyFooterItems := ASummary.FooterSummaryItems; //提取FooterItems;
//增加FooterItems
With TcxGridDBTaleSummaryItem(MyFooterItems.add) do
Begin
try
Try
Beginupdate;
Column := TcxGridDBColumn(MyTV.VisibleColumns[0]; //Footer顯示列位置
AColumn := TcxGridDBColumn(MyTV.VisibleColumns[0];
If assigned(AColumn) then
FieldName := AColumn.dataBinding.FieldName; //Footer計算欄位
Kind := TcxSummaryKind(skSum);
//skNone=無.skSum=合計;skMax=取最大值,
//skCount=//記錄數,skAverage=平均數
Finally
Endupdate;
End;
Except
Showmessage(‘error’);
MyFooterItems.Items[MyFooterItems.Count-1].Free;//報錯釋放剛加入的
End;
End;
//刪除FooterItems
MyFooterItems := TcxGridDBTableSummaryItem(MyFooterItems[0]);
If MyFooterItems.FieldByName<>’’ then
For i:= 0 to MyTV.VisibleColumnCount -1 do
Begin
AColumn := TcxGridDBColumn(MyTV.VisibleColumns[i]);
If AColumn.DataBinding.FieldName = MyFooterItems.FieldName then
Break;
End;
If Assigned(MyFooterItems.Column) then
MyFooterItems.Items[0].Free;
九、 建Band
Var MyBand : TcxGridBand;
MyBandViewInfo: TcxGridbandViewInfo;
MyBand := MyTV.Bands.Add;
MyBand.Caption : =’新建帶’;
MyBandViewInfo:= MyTV.ViewInfo.HeaderViewInfo.BandsViewInfo[MyBand.visibleIndex];
MyTV.Controller.LeftPos := MyBandViewInfo.Bounds.right;
十、 主從表明細巢狀關聯設定
MyTV.DetailKeyFieldNames := mastered; //主表關鍵列
MyTV.KeyFieldNames := ID; //子表對應關鍵列
MasterKeyFieldNames := ID;//子表自己的關鍵列
子表ADOQUERY的indexFieldNames := mastered;
十一、組設定
MyTV.DataController.Groups.FullExpand;//組展開
MyTV.DataController.Groups.Collapse;//組收縮
十二、記錄操作
MyTV.Datacontroller.Append;//增加記錄
MyTV.Datacontroller.Insert;//插入記錄
MyTV.Datacontroller.Values[0.1]:=’a’;//單元格賦值
MyTV.Datacontroller.Cancel;//取消修改
MyTV.Datacontroller.Post;//提交儲存
MyTV.Datacontroller.DeleteFocused;//刪除當前記錄
MyTV.Controller.Controller.FocusedRow.IsFirst ;//是否第一行
MyTV.Controller.Controller.FocusedRow.IsLast ;//是否最後行
MyTV.DataController.Options.FocusTopRowAfterSorting :=True;//排序後指向第一行
MyTV.ViewInfo.VisibleRecordCount ;可見行數