設置列自動寬度
這上控件的自動列寬的屬性,但是會把所有字段控制在一屏
grdblvw.OptionsView.ColumnAutoWidth:=True;
用這個方法來控制每一列的最合式寬度:
for i:=1 to grdblvw.ColumnCount-1 do
begin
grdblvw.Columns[i].ApplyBestFit();
end
清除創建列
grdblvw.ClearItems;
根據數據集自動創建字段
grdblvw.DataController.CreateAllItems;
//顯示行號的那一列
FGridDTV.OptionsView.Indicator := True;
FGridDTV.OptionsView.IndicatorWidth := 40;
//是否能選中單元格
FGridDTV.OptionsSelection.CellSelect := False;
設置行數
gridDTVGrid1DBTableView1.DataController.RecordCount := 20;
創建一列
var
aCol: TcxGridDBColumn;
begin
aCol := FGridDTV.CreateColumn;
aCol.DataBinding.FieldName := AFileName;
aCol.Caption := AShowCaption;
aCol.Width := AWidth;
case AColShowType of
gctSting: aCol.DataBinding.ValueTypeClass := TcxStringValueType;
gctInt: aCol.DataBinding.ValueTypeClass := TcxIntegerValueType;
gctFloat: aCol.DataBinding.ValueTypeClass := TcxFloatValueType;
// gctDate: aCol.DataBinding.ValueTypeClass := ; //日期類型是什麼,沒有找到 2014-12-02
gctDateTime: aCol.DataBinding.ValueTypeClass := TcxDateTimeValueType;
gctBoolen: aCol.DataBinding.ValueTypeClass := TcxBooleanValueType;
else
aCol.DataBinding.ValueTypeClass := TcxStringValueType;
end;
設置單元格回車跳轉到下一個單元格,在最後一個單元格的時候跳轉到下一行
FGridDTV.OptionsBehavior.GoToNextCellOnEnter := True;
FGridDTV.OptionsBehavior.FocusFirstCellOnNewRecord := True;
FGridDTV.OptionsBehavior.FocusCellOnCycle := True;
如何讓“Drag a column here to group by that column”不顯示
解決:點擊cxGrid1上的cxGrid1DBTableView1
在cxGrid1DBTableView1->optionsview->groupbybox:=false即可
注:OptionsView裏面有很多屬性可能經常要用,比如:ColumnAutoWith,Navigator等等,慢慢琢磨吧
在表格的事件(如OnEditValueChanged)裏面讀取或者寫入數據的時候要先post,不然可能數據會亂
FGridTV.DataController.Post;