CX控件记录

来源:互联网 发布:好看的帆布包品牌知乎 编辑:程序博客网 时间:2024/04/29 18:04

 设置列自动宽度

  这上控件的自动列宽的属性,但是会把所有字段控制在一屏
  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;

0 0