Delphi控件cxGrid 如何动态创建列?

[delphi] view plaincopy

  1. var i: Integer;    
  2.   Column: TcxGridDBColumn;    
  3.   cxView: TcxGridDBTableView;      
  4. begin    
  5.   cxView := Self.Levels[0].GridView as TcxGridDBTableView;    
  6.   if cxView.DataController.DataSource <> nil then    
  7.     if cxView.DataController.DataSource.DataSet <> nil then    
  8.     begin    
  9.       cxView.ClearItems;    
  10.       for i:=0 to  cxView.DataController.DataSource.DataSet.FieldCount-1 do     
  11.         begin    
  12.          Column := cxView.CreateColumn;    
  13.          Column.DataBinding.FieldName := cxView.DataController.DataSource.DataSet.Fields[i].FieldName;    
  14.          Column.PropertiesClass := TcxTextEditProperties;    
  15.       end;    
  16.     end;    
  17. end;   
原文地址:https://www.cnblogs.com/martian6125/p/9631099.html