home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / kolekce / d456 / DCSLIB25.ZIP / DCColumnEdit.pas < prev    next >
Pascal/Delphi Source File  |  2001-06-25  |  18KB  |  664 lines

  1. {
  2.  BUSINESS CONSULTING
  3.  s a i n t - p e t e r s b u r g
  4.  
  5.          Components Library for Borland Delphi 4.x, 5.x
  6.          Copyright (c) 1998-2000 Alex'EM
  7.  
  8. }
  9. unit DCColumnEdit;
  10.  
  11. interface
  12. {$I DCConst.inc}
  13.  
  14. uses
  15.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  16.   StdCtrls, ImgList, ComCtrls, ToolWin,
  17.   {$IFDEF DELPHI_V6}
  18.     DesignIntf, DesignEditors, DesignWindows,
  19.   {$ELSE}
  20.     Dsgnintf, DsgnWnds,
  21.   {$ENDIF}
  22.   ActnList, Menus, StdActns, DCChoice, DCDBGrids;
  23.  
  24. type
  25.   TColumnEditForm = class(TDesignWindow)
  26.     ToolBar: TToolBar;
  27.     tbNew: TToolButton;
  28.     tbDelete: TToolButton;
  29.     tbSeparator: TToolButton;
  30.     imToolBar: TImageList;
  31.     tbAll: TToolButton;
  32.     tbDefault: TToolButton;
  33.     ColumnsActionList: TActionList;
  34.     aNew: TAction;
  35.     aDelete: TAction;
  36.     aAll: TAction;
  37.     aDefault: TAction;
  38.     PopupMenu: TPopupMenu;
  39.     aToolBar: TAction;
  40.     AddField1: TMenuItem;
  41.     Delete1: TMenuItem;
  42.     aSelectAll: TAction;
  43.     SelectAll1: TMenuItem;
  44.     N1: TMenuItem;
  45.     AddAllFields1: TMenuItem;
  46.     RestoreDefault1: TMenuItem;
  47.     lvColumns: TListView;
  48.     ToolBar1: TMenuItem;
  49.     aDeleteAll: TAction;
  50.     procedure FormCreate(Sender: TObject);
  51.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  52.     procedure aNewExecute(Sender: TObject);
  53.     procedure aDeleteExecute(Sender: TObject);
  54.     procedure aDeleteAllExecute(Sender: TObject);
  55.     procedure aAllExecute(Sender: TObject);
  56.     procedure aToolBarExecute(Sender: TObject);
  57.     procedure aDefaultExecute(Sender: TObject);
  58.     procedure UpdateColumns;
  59.     procedure lvColumnsChange(Sender: TObject; Item: TListItem;
  60.       Change: TItemChange);
  61.     procedure aSelectAllExecute(Sender: TObject);
  62.     function CheckCollection: Boolean;
  63.     procedure FormResize(Sender: TObject);
  64.     procedure lvColumnsDragOver(Sender, Source: TObject; X, Y: Integer;
  65.       State: TDragState; var Accept: Boolean);
  66.     procedure lvColumnsDragDrop(Sender, Source: TObject; X, Y: Integer);
  67.   protected
  68.     function UniqueName(Component: TComponent): string; override;
  69.     procedure Activated; override;
  70.   private
  71.     { Private declarations }
  72.     FDCGridEdit: TDCGridEdit;
  73.     FClosing: boolean;
  74.     procedure SetDCGridEdit(const Value: TDCGridEdit);
  75.   public
  76.     property DCGridEdit: TDCGridEdit read FDCGridEdit  write SetDCGridEdit;
  77.     {$IFDEF DELPHI_V6}
  78.       procedure ItemDeleted(const ADesigner: IDesigner; AItem: TPersistent); override;
  79.       procedure DesignerClosed(const ADesigner: IDesigner; AGoingDormant: Boolean); override;
  80.       procedure ItemsModified(const ADesigner: IDesigner); override;
  81.     {$ELSE}
  82.       procedure FormModified; override;
  83.       procedure FormClosed(Form: TCustomForm); override;
  84.       procedure ComponentDeleted(Component: IPersistent); override;
  85.     {$ENDIF}
  86.   end;
  87.  
  88.   TColumnsProperty = class(TClassProperty)
  89.   public
  90.     procedure Edit; override;
  91.     function GetValue: string; override;
  92.     function GetAttributes: TPropertyAttributes; override;
  93.   end;
  94.  
  95.   TColumnsEditor = class(TDefaultEditor)
  96.   protected
  97.    {$IFDEF DELPHI_V6}
  98.       procedure EditProperty(const Prop: IProperty;
  99.         var Continue: Boolean); override;
  100.    {$ELSE}
  101.       procedure EditProperty(PropertyEditor: TPropertyEditor;
  102.         var Continue, FreeEditor: Boolean); override;
  103.    {$ENDIF}
  104.   public
  105.     procedure ExecuteVerb(Index: Integer); override;
  106.     function GetVerb(Index: Integer): string; override;
  107.     function GetVerbCount: Integer; override;
  108.   end;
  109.  
  110. var
  111.   ColumnEditForm: TColumnEditForm;
  112.  
  113. implementation
  114.  
  115. {$R *.DFM}
  116. //{$R DCCOlEdit.RES}
  117.  
  118. const
  119.  bmNew    = 'DBC_NEW';
  120.  bmDelete = 'DBC_DELETE';
  121.  bmAll    = 'DBC_ALL';
  122.  bmDefault= 'DBC_DEFAULT';
  123.  
  124.  fmtListViewItem = '%2.2d - TColumn: %s';
  125.  
  126. // TDBGridColumns Component Property
  127. procedure TColumnsProperty.Edit;
  128. var
  129.   ColumnsEditor: TColumnEditForm;
  130.   ADCGridEdit: TDCGridEdit;
  131.   I: integer;
  132. begin
  133.   ColumnsEditor := nil;
  134.   ADCGridEdit :=  TDCGridEdit(GetComponent(0));
  135.  
  136.   if ADCGridEdit = nil then Exit;
  137.  
  138.   {  If ColumnsEditor fo ADCGridEdit not found create it
  139.     esle SetFocus }
  140.  
  141.   {Attempt to Find it}
  142.   for I := 0 to Screen.FormCount - 1 do begin
  143.     if Screen.Forms[I] is TColumnEditForm then
  144.       if (TColumnEditForm(Screen.Forms[I]).DCGridEdit = ADCGridEdit) and
  145.          (TColumnEditForm(Screen.Forms[I]).Name = ADCGridEdit.Name+'_'+GetName)
  146.       then begin
  147.         { Great!. Find }
  148.         ColumnsEditor := TColumnEditForm(Screen.Forms[I]);
  149.         Break;
  150.       end;
  151.   end;
  152.  
  153.   if ColumnsEditor = nil then
  154.   begin
  155.     ColumnsEditor := TColumnEditForm.Create(Application);
  156.     try
  157.       {$IFDEF DELPHI_V6}
  158.         ColumnsEditor.Designer := IDesigner(Designer);
  159.       {$ELSE}
  160.         ColumnsEditor.Designer := IFormDesigner(Designer);
  161.       {$ENDIF}
  162.       ColumnsEditor.DCGridEdit := ADCGridEdit;
  163.       ColumnsEditor.Name := ADCGridEdit.Name + '_' + GetName;
  164.       with ColumnsEditor do
  165.         Caption := 'Editing ' + DCGridEdit.Name + '.' + GetName;
  166.       ColumnsEditor.Show;
  167.     except
  168.       ColumnsEditor.Free;
  169.       raise;
  170.     end;
  171.   end
  172.   else begin
  173.     ColumnsEditor.Show;
  174.     if ColumnsEditor.WindowState = wsMinimized then
  175.       ColumnsEditor.WindowState := wsNormal;
  176.   end;
  177. end;
  178.  
  179. function TColumnsProperty.GetValue: string;
  180. begin
  181.   Result := Format('(%s)', [GetPropType^.Name]);
  182. end;
  183.  
  184. function TColumnsProperty.GetAttributes: TPropertyAttributes;
  185. begin
  186.   Result := inherited GetAttributes + [paDialog] - [paSubProperties];
  187. end;
  188.  
  189. {$IFDEF DELPHI_V6}
  190.  
  191.   procedure TColumnsEditor.EditProperty(const Prop: IProperty;
  192.     var Continue: Boolean);
  193.    var
  194.     PropName: string;
  195.   begin
  196.     PropName := Prop.GetName;
  197.     if (CompareText(PropName, 'COLUMNS') = 0) then
  198.     begin
  199.       Prop.Edit;
  200.       Continue := False;
  201.     end;
  202.   end;
  203.  
  204. {$ELSE}
  205.  
  206.   procedure TColumnsEditor.EditProperty(PropertyEditor: TPropertyEditor;
  207.     var Continue, FreeEditor: Boolean);
  208.    var
  209.     PropName: string;
  210.   begin
  211.     PropName := PropertyEditor.GetName;
  212.     if (CompareText(PropName, 'COLUMNS') = 0) then
  213.     begin
  214.       PropertyEditor.Edit;
  215.       Continue := False;
  216.     end;
  217.   end;
  218.  
  219. {$ENDIF}
  220.  
  221. function TColumnsEditor.GetVerbCount: Integer;
  222. begin
  223.   Result := 1;
  224. end;
  225.  
  226. function TColumnsEditor.GetVerb(Index: Integer): string;
  227. begin
  228.   if Index = 0 then
  229.     Result := 'Co&lumns Editor ...'
  230.   else Result := '';
  231. end;
  232.  
  233. procedure TColumnsEditor.ExecuteVerb(Index: Integer);
  234. begin
  235.   if Index = 0 then Edit;
  236. end;
  237.  
  238.  
  239. function TColumnEditForm.CheckCollection: Boolean;
  240. begin
  241.   Result := (DCGridEdit <> nil) and (DCGridEdit.Columns <> nil)
  242.   {$IFDEF DELPHI_V6}
  243.     and (Designer.Root <> nil);
  244.   {$ELSE}
  245.     and (Designer.Form <> nil);
  246.   {$ENDIF}
  247. end;
  248.  
  249. procedure TColumnEditForm.SetDCGridEdit(const Value: TDCGridEdit);
  250. begin
  251.   if FDCGridEdit <> Value then begin
  252.     FDCGridEdit := Value;
  253.     UpdateColumns;
  254.   end;
  255. end;
  256.  
  257. procedure TColumnEditForm.FormCreate(Sender: TObject);
  258.  var
  259.   Bmp: TBitmap;
  260. begin
  261.   {Initialize Images}
  262.   inherited;
  263.  
  264.   Bmp := TBitmap.Create;
  265.  
  266.   imToolBar.Clear;
  267.  
  268.   Bmp.LoadFromResourceName(HInstance, bmNew);    // 0
  269.   imToolBar.AddMasked(Bmp, clBtnFace);
  270.   Bmp.LoadFromResourceName(HInstance, bmDelete); // 1
  271.   imToolBar.AddMasked(Bmp, clBtnFace);
  272.   Bmp.LoadFromResourceName(HInstance, bmAll);    // 2
  273.   imToolBar.AddMasked(Bmp, clBtnFace);
  274.   Bmp.LoadFromResourceName(HInstance, bmDefault);// 3
  275.   imToolBar.AddMasked(Bmp, clBtnFace);
  276.  
  277.   aNew.ImageIndex     := 0;
  278.   aDelete.ImageIndex  := 1;
  279.   aAll.ImageIndex     := 2;
  280.   aDefault.ImageIndex := 3;
  281.  
  282.   Bmp.Free;
  283. end;
  284.  
  285. procedure TColumnEditForm.FormClose(Sender: TObject;
  286.   var Action: TCloseAction);
  287. begin
  288.   Action := caFree;
  289. end;
  290.  
  291. procedure TColumnEditForm.aNewExecute(Sender: TObject);
  292. begin
  293.   {Add New Field}
  294.   DCGridEdit.Columns.Add;
  295.   UpdateColumns;
  296.   Designer.Modified;
  297.   lvColumns.Items[lvColumns.Items.Count-1].Selected := True;
  298.   lvColumnsChange(nil,nil,ctState);
  299. end;
  300.  
  301. procedure TColumnEditForm.aDeleteAllExecute(Sender: TObject);
  302.  var
  303.   I:Integer;
  304.   {$IFDEF DELPHI_V5UP}
  305.     FComponents: IDesignerSelections;
  306.   {$ELSE}
  307.     FComponents: TComponentList;
  308.   {$ENDIF}
  309. begin
  310.   {Delete All Fiedls}
  311.  
  312.   {$IFNDEF DELPHI_V5UP}
  313.      FComponents := TComponentList.Create;
  314.   {$ELSE}
  315.      FComponents := CreateSelectionList;
  316.   {$ENDIF}
  317.   try
  318.     DCGridEdit.Columns.BeginUpdate;
  319.     lvColumns.Items.BeginUpdate;
  320.  
  321.     for I := lvColumns.Items.Count - 1 downto 0 do
  322.      if Assigned(lvColumns.Items[i].Data)
  323.      then begin
  324.       {$IFDEF DELPHI_V5}
  325.          FComponents.Add(MakeIPersistent(TColumn(lvColumns.Items[i].Data)));
  326.       {$ELSE}
  327.          FComponents.Add(TColumn(lvColumns.Items[i].Data));
  328.       {$ENDIF}
  329.      end;
  330.     lvColumns.Items.Clear;
  331.  
  332.     for I := 0 to FComponents.Count - 1 do
  333.       {$IFDEF DELPHI_V5}
  334.          ExtractPersistent(FComponents[i]).Free;
  335.       {$ELSE}
  336.          FComponents[i].Free;
  337.       {$ENDIF}
  338.   finally
  339.     lvColumns.Items.EndUpdate;
  340.     DCGridEdit.Columns.EndUpdate;
  341.     {$IFNDEF DELPHI_V5UP}
  342.       FComponents.Free;
  343.     {$ENDIF}
  344.     Designer.Modified;
  345.   end;
  346. end;
  347.  
  348. procedure TColumnEditForm.aDeleteExecute(Sender: TObject);
  349.  var
  350.   I, SelectedItem:Integer;
  351.   {$IFDEF DELPHI_V5UP}
  352.     FComponents: IDesignerSelections;
  353.   {$ELSE}
  354.     FComponents: TComponentList;
  355.   {$ENDIF}
  356. begin
  357.   {Delete Selected Fiedls}
  358.   SelectedItem := -1;
  359.   if (lvColumns.SelCount > 0) then begin
  360.     {$IFNDEF DELPHI_V5UP}
  361.        FComponents := TComponentList.Create;
  362.     {$ELSE}
  363.        FComponents := CreateSelectionList;
  364.     {$ENDIF}
  365.     try
  366.       DCGridEdit.Columns.BeginUpdate;
  367.       lvColumns.Items.BeginUpdate;
  368.       SelectedItem := lvColumns.Items.IndexOf(lvColumns.Selected);
  369.  
  370.       for I := lvColumns.Items.Count - 1 downto 0 do
  371.         if (lvColumns.Items[i].Selected = True) and
  372.             Assigned(lvColumns.Items[i].Data)
  373.         then begin
  374.           {$IFDEF DELPHI_V5}
  375.              FComponents.Add(MakeIPersistent(TColumn(lvColumns.Items[i].Data)));
  376.           {$ELSE}
  377.              FComponents.Add(TColumn(lvColumns.Items[i].Data));
  378.           {$ENDIF}
  379.         end;
  380.  
  381.       lvColumns.Items.Clear;
  382.  
  383.       for I := 0 to FComponents.Count - 1 do
  384.         {$IFDEF DELPHI_V5}
  385.            ExtractPersistent(FComponents[i]).Free;
  386.         {$ELSE}
  387.            FComponents[i].Free;
  388.         {$ENDIF}
  389.     finally
  390.       lvColumns.Items.EndUpdate;
  391.       DCGridEdit.Columns.EndUpdate;
  392.       {$IFNDEF DELPHI_V5UP}
  393.         FComponents.Free;
  394.       {$ENDIF}
  395.       Designer.Modified;
  396.       if (lvColumns.Items.Count > 0) then
  397.         if (SelectedItem > lvColumns.Items.Count - 1) then
  398.            lvColumns.Items[lvColumns.Items.Count-1].Selected := True
  399.         else
  400.            lvColumns.Items[SelectedItem].Selected := True;
  401.         lvColumnsChange(nil,nil,ctState);
  402.     end;
  403.    end;
  404. end;
  405.  
  406. procedure TColumnEditForm.aAllExecute(Sender: TObject);
  407.  var
  408.    I: Integer;
  409.    Column: TColumn;
  410. begin
  411.   {Add All Fields}
  412.   for I := 0 to DCGridEdit.DataSet.FieldCount - 1 do
  413.   begin
  414.     Column := DCGridEdit.Columns.Add;
  415.     Column.FieldName := DCGridEdit.DataSet.Fields[i].FieldName;
  416.   end;
  417.   UpdateColumns;
  418.   Designer.Modified;
  419. end;
  420.  
  421. procedure TColumnEditForm.aToolBarExecute(Sender: TObject);
  422. begin
  423.   aToolBar.Checked := not aToolBar.Checked;
  424.   ToolBar.Visible  := aToolBar.Checked
  425. end;
  426.  
  427. procedure TColumnEditForm.aDefaultExecute(Sender: TObject);
  428.  var
  429.   I:Integer;
  430.   ListItem: TListItem;
  431. begin
  432.   {Restore Default}
  433.   if (lvColumns.SelCount > 0) then begin
  434.     ListItem := lvColumns.Selected;
  435.     for i := 0 to lvColumns.SelCount - 1 do begin
  436.       TColumn(ListItem.Data).RestoreDefaults;
  437.       ListItem := lvColumns.GetNextItem(ListItem,sdBelow,[isSelected]);
  438.     end;
  439.     lvColumnsChange(nil,nil,ctState);
  440.     Designer.Modified;
  441.   end;
  442. end;
  443.  
  444. procedure TColumnEditForm.UpdateColumns;
  445.  var
  446.   I: longint;
  447.   UpdateColumns: boolean;
  448.   ListItem: TListItem;
  449. begin
  450.   if not CheckCollection then
  451.   begin
  452.     lvColumns.Items.Clear;
  453.     lvColumnsChange(nil,nil,ctState);
  454.     Exit;
  455.   end;
  456.  
  457.   lvColumns.StateImages := DCGridEdit.Images;
  458.  
  459.   UpdateColumns := (lvColumns.Items.Count <> DCGridEdit.Columns.Count );
  460.   I := 0;
  461.   while not(UpdateColumns) and (I <= DCGridEdit.Columns.Count - 1) do
  462.   begin
  463.     UpdateColumns := (lvColumns.Items[I].Data <> DCGridEdit.Columns[I]);
  464.     Inc(I);
  465.   end;
  466.  
  467.   if UpdateColumns then
  468.   begin
  469.     lvColumns.Items.BeginUpdate;
  470.     lvColumns.Items.Clear;
  471.       try
  472.         if (DCGridEdit.Columns.State = csCustomized) then
  473.            for I := 0 to DCGridEdit.Columns.Count - 1 do
  474.            begin
  475.              ListItem := lvColumns.Items.Add;
  476.              ListItem.Caption := Format(fmtListViewItem,[I,DCGridEdit.Columns[i].DisplayName]);
  477.              ListItem.Data := DCGridEdit.Columns[i];
  478.              ListItem.StateIndex := DCGridEdit.Columns[i].ItemIndex;
  479.            end;
  480.       finally
  481.         lvColumns.Items.EndUpdate;
  482.       end;
  483.   end else
  484.     for I := 0 to DCGridEdit.Columns.Count - 1 do
  485.     begin
  486.         lvColumns.Items[i].Caption    := Format(fmtListViewItem,[I,DCGridEdit.Columns[i].DisplayName]);
  487.         lvColumns.Items[i].StateIndex := DCGridEdit.Columns[i].ItemIndex;
  488.     end;
  489.   lvColumnsChange(nil,nil,ctState);
  490. end;
  491.  
  492.  
  493. procedure TColumnEditForm.lvColumnsChange(Sender: TObject; Item: TListItem;
  494.   Change: TItemChange);
  495.  var
  496.   {$IFDEF DELPHI_V5UP}
  497.     {$IFDEF DELPHI_V6}
  498.        FComponents: IDesignerSelections;
  499.     {$ELSE}
  500.        FComponents: TDesignerSelectionList;
  501.     {$ENDIF}
  502.   {$ELSE}
  503.     FComponents: TComponentList;
  504.   {$ENDIF}
  505.   I: Integer;
  506. begin
  507.    {Check Caption Staus}
  508.    aDelete.Enabled    := lvColumns.SelCount > 0;
  509.    aAll.Enabled       := Assigned(DCGridEdit) and
  510.                          Assigned(DCGridEdit.DataSet) and
  511.                          (DCGridEdit.DataSet.FieldCount > 0) and
  512.                          (lvColumns.Items.Count = 0);
  513.    aDefault.Enabled   := (lvColumns.SelCount > 0);
  514.    aSelectAll.Enabled := (lvColumns.Items.Count > 0);
  515.  
  516.   if CheckCollection and Active then
  517.   begin
  518.     {$IFNDEF DELPHI_V5UP}
  519.       FComponents := TComponentList.Create;
  520.     {$ELSE}
  521.       {$IFDEF DELPHI_V6}
  522.          FComponents := CreateSelectionList;
  523.       {$ELSE}
  524.          FComponents := TDesignerSelectionList.Create;
  525.       {$ENDIF}
  526.     {$ENDIF}
  527.     if (lvColumns.SelCount > 0) then begin
  528.       for i := lvColumns.Items.Count - 1 downto 0 do
  529.         if (lvColumns.Items[i].Selected = True) and
  530.            Assigned(lvColumns.Items[i].Data)
  531.         then
  532.           FComponents.Add(TColumn(lvColumns.Items[i].Data));
  533.     end
  534.     else
  535.       FComponents.Add(DCGridEdit.Columns);
  536.     SetSelection(FComponents);
  537.   end;
  538.  
  539. end;
  540.  
  541. procedure TColumnEditForm.Activated;
  542. begin
  543.   lvColumnsChange(nil,nil,ctState);
  544. end;
  545.  
  546. function TColumnEditForm.UniqueName(Component: TComponent): string;
  547. var
  548.   Temp: string;
  549. begin
  550.   if (Component <> nil) then Temp := Component.ClassName
  551.   else Temp := TColumn.ClassName;
  552.   if (UpCase(Temp[1]) = 'T') and (Length(Temp) > 1) then
  553.     System.Delete(Temp, 1, 1);
  554.   Result := Designer.UniqueName(Temp);
  555. end;
  556.  
  557. {$IFDEF DELPHI_V6}
  558.  
  559.   procedure TColumnEditForm.DesignerClosed(const ADesigner: IDesigner;
  560.     AGoingDormant: Boolean);
  561.   begin
  562.     if Designer = ADesigner then
  563.     begin
  564.       FClosing := True;
  565.       Close;
  566.     end;
  567.   end;
  568.  
  569.   procedure TColumnEditForm.ItemDeleted(const ADesigner: IDesigner;
  570.     AItem: TPersistent);
  571.   begin
  572.     if (AItem = nil) or FClosing then Exit;
  573.     if AItem = DCGridEdit then
  574.     begin
  575.       FDCGridEdit := nil;
  576.       Close;
  577.     end;
  578.   end;
  579.  
  580.   procedure TColumnEditForm.ItemsModified(const ADesigner: IDesigner);
  581.   begin
  582.     if FClosing then exit;
  583.     if not (csDestroying in ComponentState) then UpdateColumns;
  584.   end;
  585.  
  586. {$ELSE}
  587.  
  588.   procedure TColumnEditForm.FormModified;
  589.   begin
  590.     if FClosing then Exit;
  591.     if not (csDestroying in ComponentState) then UpdateColumns;
  592.   end;
  593.  
  594.   procedure TColumnEditForm.FormClosed(Form: TCustomForm);
  595.   begin
  596.     if (Form = Designer.Form) then
  597.     begin
  598.       aDeleteAllExecute(Self);
  599.       Close;
  600.     end;
  601.   end;
  602.  
  603.   procedure TColumnEditForm.ComponentDeleted(Component: IPersistent);
  604.   begin
  605.     if ExtractPersistent(Component) = DCGridEdit then
  606.     begin
  607.       FDCGridEdit := nil;
  608.       Close;
  609.     end;
  610.   end;
  611.  
  612. {$ENDIF}
  613.  
  614. procedure TColumnEditForm.aSelectAllExecute(Sender: TObject);
  615.  var
  616.   I: integer;
  617. begin
  618.   for I := 0 to lvColumns.Items.Count - 1 do
  619.       lvColumns.Items[i].Selected := True;
  620. end;
  621.  
  622. procedure TColumnEditForm.FormResize(Sender: TObject);
  623. begin
  624.   lvColumns.Columns[0].Width := lvColumns.ClientWidth;
  625. end;
  626.  
  627. procedure TColumnEditForm.lvColumnsDragOver(Sender, Source: TObject; X,
  628.   Y: Integer; State: TDragState; var Accept: Boolean);
  629. begin
  630.   Accept := True;
  631. end;
  632.  
  633. procedure TColumnEditForm.lvColumnsDragDrop(Sender, Source: TObject; X,
  634.   Y: Integer);
  635.  var
  636.   Column: TColumn;
  637.   ColumnFrom, ColumnTarget: TColumn;
  638. begin
  639.   { Move Column                           }
  640.   { lvColumns.Selected   - Dragged Column }
  641.   { lvColumns.DropTarget                  }
  642.  
  643.   if not Assigned(Sender) or not Assigned(Source) or
  644.      not Assigned(lvColumns.DropTarget) or
  645.      not Assigned(lvColumns.Selected) or
  646.     (lvColumns.Selected.Index =  lvColumns.DropTarget.Index) then Exit;
  647.  
  648.   Column := TColumn.Create(nil);
  649.   ColumnFrom  := DCGridEdit.Columns[lvColumns.Selected.Index];
  650.   ColumnTarget:= DCGridEdit.Columns[lvColumns.DropTarget.Index];
  651.   Column.Assign(ColumnFrom);
  652.   try
  653.     ColumnFrom.Assign(ColumnTarget);
  654.     ColumnTarget.Assign(Column);
  655.   finally
  656.     Column.Free;
  657.   end;
  658.   UpdateColumns;
  659.   Designer.Modified;
  660.   lvColumnsChange(nil,nil,ctState);
  661. end;
  662.  
  663. end.
  664.