Search

'CxGrid'에 해당되는 글 1건

  1. 2009.12.08 Delphi - TcxGrid

Delphi - TcxGrid

Programming/Delphi 2009.12.08 09:54 Posted by 파란크리스마스

- Query 실행후 동적으로 컬럼 추가

(cxGridDBTableView1.DataController as IcxCustomGridDataController).DeleteAllItems;
(cxGridDBTableView1.DataController as IcxCustomGridDataController).CreateAllItems(true);
cxGridDBTableView1.ApplyBestFit();

- [Enter] 키로 Cell 이동

cxGrid1TableView1.OptionsBehavior.FocusCellOnCycle := true;
cxGrid1TableView1.OptionsBehavior.FocusCellOnTab := true;
cxGrid1TableView1.OptionsBehavior.FocusFirstCellOnNewRecord := true;
cxGrid1TableView1.OptionsBehavior.GoToNextCellOnEnter := true;

- 속성

속성명 자료형 설명
OptionsBehavior.CopyCaptionsToClipboard Boolean 클립보드에 복사할 때 캡션도 복사할지 여부
OptionsSelection.CellMultiSelect Boolean Cell 다중 선택 여부
OptionsSelection.CellSelect Boolean Cell별로 선택 가능 여부
OptionsSelection.MultiSelect Boolean Row 다중 선택 여부

- TcxCustomDataSource

TDatasetFieldModel=class(TcxCustomDataSource)
  private
    DatasetAnalyzer : TDatasetAnalyzer;
  protected
    function GetRecordCount: Integer; override;
    function GetValue(ARecordHandle: TcxDataRecordHandle; AItemHandle: TcxDataItemHandle): Variant; override;
  public
    constructor Create;
    destructor Destroy; override;
  end;

implementation

{ TDatasetFieldModel }

constructor TDatasetFieldModel.Create;
begin
  inherited Create;
  DatasetAnalyzer := TDatasetAnalyzer.Create(TDatasetField);
end;

destructor TDatasetFieldModel.Destroy;
begin
  DatasetAnalyzer.Free;
  inherited Destroy;
end;

function TDatasetFieldModel.GetRecordCount: Integer;
begin
  Result := DatasetAnalyzer.Count;
end;

function TDatasetFieldModel.GetValue(ARecordHandle: TcxDataRecordHandle; AItemHandle: TcxDataItemHandle): Variant;
var
  AColumnId: Integer;
  theField : TDatasetField;
begin
  result := Variants.Null;
  AColumnId := GetDefaultItemID(Integer(AItemHandle));

  if Integer(ARecordHandle) < Self.GetRecordCount then begin
    theField := (DatasetAnalyzer.Items[Integer(ARecordHandle)] as TDatasetField);
    if Assigned(theField) then begin
      case AColumnId of
        0 : Result := theField.FieldName;
        1 : Result := theField.DataTypeStr;
        2 : Result := theField.Size;
      end;
    end;
  end;
end;

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
begin
  DatasetFieldModel := TDatasetFieldModel.Create;
  cxGrid1TableView1.DataController.CustomDataSource := DatasetFieldModel;
end;

procedure TForm1.ListBox1Click(Sender: TObject);
begin
  if ListBox1.ItemIndex >= 0 then begin
    Table1.Active := false;
    Table1.TableName := ListBox1.Items.Strings[ListBox1.ItemIndex];
    Table1.Active := true;

    DatasetFieldModel.DatasetAnalyzer.Analyzer(Table1);
    DatasetFieldModel.DataChanged;
  end;
end;

- 한글관련 버그 수정 (Delphi 2009 이상

사이트 : http://eaglesoft.tistory.com/162

- 옵션

cxGrid1TableView1.OptionsView.GroupByBox := false;
cxGrid1TableView1.OptionsData.Editing := false;  // 읽기전용

- ??

procedure TCreateTableFrm.Col1GetProperties(
  Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
  var AProperties: TcxCustomEditProperties);
var
  rowData : TRowObject;
begin
  rowData := TRowObject(CustomGridModel.RowDataList.Items[ARecord.Index]);


  ...
end;

- 수정중인 Cell 바로 적용

cxGrid1TableView1.DataController.PostEditingData;

- end - 

신고
TAG ,


 

티스토리 툴바