Delphi 컨트롤 cxGrid는 어떻게 열을 동적으로 만듭니까?

959 단어 DELPHI
var i: Integer;  
  Column: TcxGridDBColumn;  
  cxView: TcxGridDBTableView;    
begin  
  cxView := Self.Levels[0].GridView as TcxGridDBTableView;  
  if cxView.DataController.DataSource <> nil then  
    if cxView.DataController.DataSource.DataSet <> nil then  
    begin  
      cxView.ClearItems;  
      for i:=0 to  cxView.DataController.DataSource.DataSet.FieldCount-1 do   
        begin  
         Column := cxView.CreateColumn;  
         Column.DataBinding.FieldName := cxView.DataController.DataSource.DataSet.Fields[i].FieldName;  
         Column.PropertiesClass := TcxTextEditProperties;  
      end;  
    end;  
end;  
for i := 0 to Query.FieldCount - 1 do     
begin     
   cxGrid.CreateColumn;     
   cxGrid.columns[i].DataBinding.FieldName := Query.Fields[i].DisplayName;     
   cxGrid.Columns[i].Caption := 'XXXX';     
   cxGrid.Columns[i].Width   :=80;     
end;  

좋은 웹페이지 즐겨찾기