home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 December / Chip_2001-12_cd1.bin / zkuste / delphi / kolekce / d456 / VOLGAPAK.ZIP / Source / VolDBGrided.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-09-09  |  19.2 KB  |  696 lines

  1. //---------------------------------------------------------------------------
  2. //  TVolgaDBGridColumnsEditor - columns editor for TVolgaDBGrid
  3. //---------------------------------------------------------------------------
  4. //  Copyright ⌐ 2000, Olga Vlasova, Russia
  5. //  http://volgatable.chat.ru
  6. //  E-mail: volgatable@chat.ru
  7. //---------------------------------------------------------------------------
  8. unit VolDBGridEd;
  9.  
  10. interface
  11.  
  12. {$I Volga.INC}
  13.  
  14. uses
  15.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  16.   StdCtrls, ComCtrls, ToolWin, Menus, VolDBGrid, DB,
  17.   {$IFDEF VER140} DesignIntf, DesignEditors, DesignWindows,
  18.   {$ELSE} LibIntf, DsgnIntf, DsgnWnds,{$ENDIF}
  19.   ImgList;
  20.  
  21. type
  22.   TVolgaDBGridColumnsEditor = class(TDesignWindow)
  23.     ToolBar1: TToolBar;
  24.     tbAddNew: TToolButton;
  25.     tbDeleteSelected: TToolButton;
  26.     ToolButton3: TToolButton;
  27.     tbAddAllFields: TToolButton;
  28.     tbRestoreDefaults: TToolButton;
  29.     ImageList1: TImageList;
  30.     PopupMenu1: TPopupMenu;
  31.     miAddNew: TMenuItem;
  32.     miDeleteSelected: TMenuItem;
  33.     miAddAllFields: TMenuItem;
  34.     miRestoreDefaults: TMenuItem;
  35.     miSelectAll: TMenuItem;
  36.     N1: TMenuItem;
  37.     ListView1: TListView;
  38.     ToolButton1: TToolButton;
  39.     tbUp: TToolButton;
  40.     tbDown: TToolButton;
  41.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  42.     procedure FormCreate(Sender: TObject);
  43.     procedure tbAddNewClick(Sender: TObject);
  44.     procedure tbDeleteSelectedClick(Sender: TObject);
  45.     procedure tbAddAllFieldsClick(Sender: TObject);
  46.     procedure tbRestoreDefaultsClick(Sender: TObject);
  47.     procedure ListView1Change(Sender: TObject; Item: TListItem;
  48.       Change: TItemChange);
  49.     procedure FormResize(Sender: TObject);
  50.     procedure miAddNewClick(Sender: TObject);
  51.     procedure miDeleteSelectedClick(Sender: TObject);
  52.     procedure miSelectAllClick(Sender: TObject);
  53.     procedure miAddAllFieldsClick(Sender: TObject);
  54.     procedure miRestoreDefaultsClick(Sender: TObject);
  55.     procedure tbDownClick(Sender: TObject);
  56.     procedure tbUpClick(Sender: TObject);
  57.   private
  58.     FVolgaDBGrid:TVolgaDBGrid;
  59.     function CheckCollection: Boolean;
  60.     procedure SetDBGrid(const Value: TVolgaDBGrid);
  61.     procedure UpdateData;
  62.     procedure Copy;
  63.     procedure Cut;
  64.     procedure Paste;
  65.   protected
  66.     function UniqueName(Component: TComponent): string; override;
  67.     procedure Activated; override;
  68.     { Private declarations }
  69.   public
  70. {$IFDEF VER140}
  71.     function EditAction(Action: TEditAction): Boolean; override;
  72. {$ELSE}
  73.     procedure EditAction(Action: TEditAction); override;
  74. {$ENDIF}
  75.     procedure FormModified; override;
  76.     procedure FormClosed(Form: TCustomForm); override;
  77.     function GetEditState: TEditState; override;
  78.     procedure ComponentDeleted(Component: IPersistent); override;
  79.  
  80.     property VolgaDBGrid: TVolgaDBGrid read FVolgaDBGrid
  81.          write SetDBGrid;
  82.     { Public declarations }
  83.   end;
  84.  
  85.  
  86. { TVolgaDBGridColumnsProperty }
  87.  
  88.   TVolgaDBGridColumnsProperty = class(TPropertyEditor)
  89.     function GetAttributes: TPropertyAttributes; override;
  90.     function GetValue: string; override;
  91.     procedure Edit; override;
  92.   end;
  93.  
  94. { TVolgaDBGridEditor }
  95.  
  96.   TVolgaDBGridEditor = class(TComponentEditor)
  97.     procedure ExecuteVerb(Index: Integer); override;
  98.     function GetVerb(Index: Integer): string; override;
  99.     function GetVerbCount: Integer; override;
  100.   end;
  101.  
  102. { TVolgaColumnDataFieldProperty }
  103.  
  104.   TVolgaColumnDataFieldProperty = class(TStringProperty)
  105.   public
  106.     function GetAttributes: TPropertyAttributes; override;
  107.     procedure GetValueList(List: TStrings); virtual;
  108.     procedure GetValues(Proc: TGetStrProc); override;
  109.   end;
  110.  
  111. { TVolgaColumnLookupKeyProperty }
  112.  
  113.   TVolgaColumnLookupKeyProperty = class(TStringProperty)
  114.   public
  115.     function GetAttributes: TPropertyAttributes; override;
  116.     procedure GetValueList(List: TStrings); virtual;
  117.     procedure GetValues(Proc: TGetStrProc); override;
  118.   end;
  119.  
  120. var
  121.   VolgaDBGridColumnsEditor: TVolgaDBGridColumnsEditor;
  122.  
  123. //procedure ShowItemsEditor({Designer: TDesigner;}
  124. //  AVolgaDBGrid: TVolgaDBGrid);
  125.  
  126. implementation
  127.  
  128. {$R *.DFM}
  129.  
  130. type
  131.   TDesigner = IDesigner;
  132.   TFormDesigner = IFormDesigner;
  133.  
  134. function FindEditor(AVolgaDBGrid: TVolgaDBGrid): TVolgaDBGridColumnsEditor;
  135. var
  136.   I: Integer;
  137. begin
  138.   Result := nil;
  139.   for I := 0 to Screen.FormCount - 1 do begin
  140.     if Screen.Forms[I] is TVolgaDBGridColumnsEditor then begin
  141.       if TVolgaDBGridColumnsEditor(Screen.Forms[I]).VolgaDBGrid = AVolgaDBGrid then
  142.       begin
  143.         Result := TVolgaDBGridColumnsEditor(Screen.Forms[I]);
  144.         Break;
  145.       end;
  146.     end;
  147.   end;
  148. end;
  149.  
  150. procedure ShowItemsEditor(Designer: TDesigner;
  151.   AVolgaDBGrid: TVolgaDBGrid);
  152. var
  153.   Editor: TVolgaDBGridColumnsEditor;
  154. begin
  155.   if AVolgaDBGrid = nil then Exit;
  156.   Editor := FindEditor(AVolgaDBGrid);
  157.   if Editor = nil then begin
  158.     Editor := TVolgaDBGridColumnsEditor.Create(Application);
  159.     try
  160.       Editor.Designer := TFormDesigner(Designer);
  161.       Editor.VolgaDBGrid := AVolgaDBGrid;
  162.       Editor.Show;
  163.     except
  164.       Editor.Free;
  165.       raise;
  166.     end;
  167.   end
  168.   else begin
  169.     Editor.Show;
  170.     if Editor.WindowState = wsMinimized then
  171.       Editor.WindowState := wsNormal;
  172.   end;
  173. end;
  174.  
  175.  
  176. { TDBGridColumnsEditor }
  177.  
  178. function TVolgaDBGridColumnsEditor.CheckCollection: Boolean;
  179. begin
  180.   Result := (VolgaDBGrid <> nil) and (VolgaDBGrid.Columns <> nil)
  181.     and (Designer.Form <> nil);
  182. end;
  183.  
  184. procedure TVolgaDBGridColumnsEditor.SetDBGrid(const Value: TVolgaDBGrid);
  185. begin
  186.   if FVolgaDBGrid <> Value then begin
  187.     FVolgaDBGrid := Value;
  188.     UpdateData;
  189.   end;
  190. end;
  191.  
  192. procedure TVolgaDBGridColumnsEditor.UpdateData;
  193. var
  194.   Empty,Modified: Boolean;
  195.   i:Integer;
  196.   ListItem: TListItem;
  197. begin
  198.   if CheckCollection then begin
  199.     Caption := Format('%s.Columns', [VolgaDBGrid.Name]);
  200.     Empty := VolgaDBGrid.Columns.Count = 0;
  201.   end
  202.   else Empty := True;
  203.   if Empty then begin
  204.     ListView1.Items.Clear;
  205.   end
  206.   else begin
  207.     Modified := False;
  208.     if (VolgaDBGrid.Columns.Count <> ListView1.Items.Count) then Modified := True;
  209.     if (Modified = False) then
  210.       for i := 0 to VolgaDBGrid.Columns.Count - 1 do
  211.         if (ListView1.Items[i].Data <> VolgaDBGrid.Columns[i]) then begin
  212.           Modified := True;
  213.           Break;
  214.         end;
  215.     if (Modified = True) then begin
  216.       ListView1.Items.BeginUpdate;
  217.       ListView1.Items.Clear;
  218.       try
  219.         if (VolgaDBGrid.Columns.State = csCustomized) then begin
  220.            for i := 0 to VolgaDBGrid.Columns.Count - 1 do begin
  221.              ListItem := ListView1.Items.Add;
  222.              ListItem.Caption := IntToStr(i) + ' - ' + VolgaDBGrid.Columns[i].DisplayName;
  223.              ListItem.Data := VolgaDBGrid.Columns[i];
  224.            end;
  225.         end;
  226.       finally
  227.         ListView1.Items.EndUpdate;
  228.       end;
  229.     end else // ╟απεδεΓεΩ ∞εµσ≥ ∩ε∞σφ ≥ⁿ±  ΩεπΣα ∞σφ ■≥ FieldName
  230.       for i := 0 to VolgaDBGrid.Columns.Count - 1 do
  231.         ListView1.Items[i].Caption := IntToStr(i) + ' - ' + VolgaDBGrid.Columns[i].DisplayName;
  232.   end;
  233.   ListView1Change(nil,nil,ctState);
  234. end;
  235.  
  236. procedure TVolgaDBGridColumnsEditor.FormClose(Sender: TObject;
  237.   var Action: TCloseAction);
  238. begin
  239.   Action := caFree;
  240. end;
  241.  
  242. procedure TVolgaDBGridColumnsEditor.FormCreate(Sender: TObject);
  243. begin
  244.   VolgaDBGrid := nil;
  245.   if NewStyleControls then Font.Style := [];
  246. end;
  247.  
  248. procedure TVolgaDBGridColumnsEditor.tbAddNewClick(Sender: TObject);
  249. begin
  250.   VolgaDBGrid.Columns.Add;
  251.   UpdateData;
  252.   Designer.Modified;
  253.   ListView1.Items[ListView1.Items.Count-1].Selected := True;
  254.   ListView1Change(nil,nil,ctState);
  255. end;
  256.  
  257. procedure TVolgaDBGridColumnsEditor.tbDeleteSelectedClick(Sender: TObject);
  258. var i,sel:Integer;
  259. {$IFDEF Delphi4}
  260.   FComponents: TComponentList;
  261. {$ELSE}
  262.   FComponents: TDesignerSelectionList;
  263. {$ENDIF}
  264. begin
  265.   sel := -1;
  266.   if (ListView1.SelCount > 0) then begin
  267. {$IFDEF Delphi4}
  268.     FComponents := TComponentList.Create;
  269. {$ELSE}
  270.     FComponents := TDesignerSelectionList.Create;
  271. {$ENDIF}
  272.     try
  273.       VolgaDBGrid.Columns.BeginUpdate;
  274.       ListView1.Items.BeginUpdate;
  275.       sel := ListView1.Items.IndexOf(ListView1.Selected);
  276.       for i := ListView1.Items.Count - 1 downto 0 do
  277.        if (ListView1.Items[i].Selected = True) and Assigned(ListView1.Items[i].Data) then begin
  278. {$IFDEF Delphi4}
  279.          FComponents.Add(TVolgaColumn(ListView1.Items[i].Data));
  280. {$ELSE}
  281.          FComponents.Add(ListView1.Items[i].Data);
  282. {$ENDIF}
  283.        end;
  284.       ListView1.Items.Clear;
  285.  
  286.       for i := 0 to FComponents.Count - 1 do FComponents[i].Free;
  287.     finally
  288.       ListView1.Items.EndUpdate;
  289.       VolgaDBGrid.Columns.EndUpdate;
  290.       FComponents.Free;
  291.       Designer.Modified;
  292.       if (ListView1.Items.Count > 0) then
  293.         if (sel > ListView1.Items.Count - 1) then
  294.            ListView1.Items[ListView1.Items.Count-1].Selected := True
  295.         else
  296.            ListView1.Items[sel].Selected := True;
  297.       ListView1Change(nil,nil,ctState);
  298.     end;
  299.    end;
  300. end;
  301.  
  302. procedure TVolgaDBGridColumnsEditor.tbAddAllFieldsClick(Sender: TObject);
  303. var msgValue:Word;
  304.     i:Integer;
  305.     Col:TVolgaColumn;
  306. begin
  307.   if (VolgaDBGrid.Columns.State = csDefault) then
  308.     VolgaDBGrid.Columns.State := csCustomized
  309.   else begin
  310.    if (VolgaDBGrid.Columns.Count > 0) then begin
  311.      msgValue := MessageDlg('Delete all columns?',
  312.        mtConfirmation, [mbYes, mbNo, mbCancel], 0);
  313.      case msgValue of
  314.        mrYes: VolgaDBGrid.Columns.Clear;
  315.        mrCancel: Exit;
  316.      end;
  317.    end;
  318.    for i := 0 to VolgaDBGrid.DataSource.DataSet.FieldCount - 1 do begin
  319.      Col := VolgaDBGrid.Columns.Add;
  320.      Col.FieldName := VolgaDBGrid.DataSource.DataSet.Fields[i].FieldName;
  321.    end;
  322.   end;
  323.   UpdateData;
  324.   Designer.Modified;
  325. end;
  326.  
  327. procedure TVolgaDBGridColumnsEditor.tbRestoreDefaultsClick(Sender: TObject);
  328. var i:Integer;
  329.   ListItem: TListItem;
  330. begin
  331.   if (ListView1.SelCount > 0) then begin
  332.     ListItem := ListView1.Selected;
  333.     for i := 0 to ListView1.SelCount - 1 do begin
  334.       TVolgaColumn(ListItem.Data).RestoreDefaults;
  335.       ListItem := ListView1.GetNextItem(ListItem,sdBelow,[isSelected]);
  336.     end;
  337.     ListView1Change(nil,nil,ctState);
  338.     Designer.Modified;
  339.   end;
  340. end;
  341.  
  342. procedure TVolgaDBGridColumnsEditor.ListView1Change(Sender: TObject;
  343.   Item: TListItem; Change: TItemChange);
  344. var
  345. {$IFDEF Delphi4}
  346.   FComponents: TComponentList;
  347. {$ELSE}
  348.   FComponents: TDesignerSelectionList;
  349. {$ENDIF}
  350.   i: Integer;
  351. begin
  352.   if (Change <> ctState)  then Exit;
  353.   tbDeleteSelected.Enabled := ListView1.SelCount > 0;
  354.   tbRestoreDefaults.Enabled := ListView1.Items.Count > 0;
  355.  
  356.   miDeleteSelected.Enabled := ListView1.SelCount > 0;
  357.   miRestoreDefaults.Enabled := ListView1.Items.Count > 0;
  358.   miSelectAll.Enabled := ListView1.Items.Count > 0;
  359.   tbAddAllFields.Enabled := Assigned(VolgaDBGrid) and Assigned(VolgaDBGrid.DataSource) and
  360.     Assigned(VolgaDBGrid.Datasource.Dataset) and (VolgaDBGrid.Datasource.Dataset.FieldCount > 0);
  361.  
  362.   if CheckCollection and Active then begin
  363. {$IFDEF Delphi4}
  364.      FComponents := TComponentList.Create;
  365. {$ELSE}
  366.      FComponents := TDesignerSelectionList.Create;
  367. {$ENDIF}
  368.     if (ListView1.SelCount > 0) then begin
  369.       for i := ListView1.Items.Count - 1 downto 0 do
  370.        if (ListView1.Items[i].Selected = True) and Assigned(ListView1.Items[i].Data) then
  371. {$IFDEF Delphi4}
  372.          FComponents.Add(TVolgaColumn(ListView1.Items[i].Data));
  373. {$ELSE}
  374.          FComponents.Add(ListView1.Items[i].Data);
  375. {$ENDIF}
  376.     end
  377.     else FComponents.Add(VolgaDBGrid.Columns);
  378.     SetSelection(FComponents);
  379.   end;
  380. end;
  381.  
  382. procedure TVolgaDBGridColumnsEditor.Activated;
  383. begin
  384.   ListView1Change(nil,nil,ctState);
  385. end;
  386.  
  387. function TVolgaDBGridColumnsEditor.UniqueName(Component: TComponent): string;
  388. var
  389.   Temp: string;
  390. begin
  391.   if (Component <> nil) then Temp := Component.ClassName
  392.   else Temp := TVolgaColumn.ClassName;
  393.   if (UpCase(Temp[1]) = 'T') and (Length(Temp) > 1) then
  394.     System.Delete(Temp, 1, 1);
  395.   Result := Designer.UniqueName(Temp);
  396. end;
  397.  
  398. {$IFDEF VER140}
  399. function TVolgaDBGridColumnsEditor.EditAction(Action: TEditAction): Boolean;
  400. {$ELSE}
  401. procedure TVolgaDBGridColumnsEditor.EditAction(Action: TEditAction);
  402. {$ENDIF}
  403. begin
  404.   case Action of
  405.     eaCut: Cut;
  406.     eaCopy: Copy;
  407.     eaPaste: Paste;
  408.     eaDelete: tbDeleteSelectedClick(Self);
  409.   end;
  410. {$IFDEF VER140}
  411.   REsult := true;
  412. {$ENDIF}
  413. end;
  414.  
  415. procedure TVolgaDBGridColumnsEditor.Copy;
  416. var
  417. {$IFDEF Delphi4}
  418.   CompList: TComponentList;
  419. {$ELSE}
  420.   CompList: TDesignerSelectionList;
  421. {$ENDIF}
  422.   ListItem: TListItem;
  423.   i:Integer;
  424. begin
  425. {$IFDEF Delphi4}
  426.   CompList := TComponentList.Create;
  427. {$ELSE}
  428.   CompList := TDesignerSelectionList.Create;
  429. {$ENDIF}
  430.   try
  431.     if (ListView1.SelCount > 0) then begin
  432.       ListItem := ListView1.Selected;
  433.       for i := 0 to ListView1.SelCount - 1 do begin
  434. {$IFDEF Delphi4}
  435.         CompList.Add(TVolgaColumn(ListItem.Data));
  436. {$ELSE}
  437.         CompList.Add(ListItem.Data);
  438. {$ENDIF}
  439.         ListItem := ListView1.GetNextItem(ListItem,sdBelow,[isSelected]);
  440.       end;
  441.     end;
  442.   finally
  443.     CompList.Free;
  444.   end;
  445. end;
  446.  
  447. procedure TVolgaDBGridColumnsEditor.Cut;
  448. begin
  449.   Copy;
  450.   tbDeleteSelectedClick(Self);
  451. end;
  452.  
  453. procedure TVolgaDBGridColumnsEditor.Paste;
  454. {$IFDEF Delphi4}
  455. var CompList: TComponentList;
  456. {$ELSE}
  457. var CompList: TDesignerSelectionList;
  458. {$ENDIF}
  459. begin
  460.   if CheckCollection then begin
  461. {$IFDEF Delphi4}
  462.     CompList := TComponentList.Create;
  463. {$ELSE}
  464.     CompList := TDesignerSelectionList.Create;
  465. {$ENDIF}
  466.     try
  467.       UpdateData;
  468.     finally
  469.       CompList.Free;
  470.     end;
  471.   end;
  472. end;
  473.  
  474. procedure TVolgaDBGridColumnsEditor.FormModified;
  475. begin
  476.   if not (csDestroying in ComponentState) then UpdateData;
  477. end;
  478.  
  479. procedure TVolgaDBGridColumnsEditor.FormClosed(Form: TCustomForm);
  480. begin
  481.   if Form = Designer.Form then Close;
  482. end;
  483.  
  484. procedure TVolgaDBGridColumnsEditor.ComponentDeleted(Component: IPersistent);
  485. begin
  486.   if ExtractPersistent(Component) = VolgaDBGrid then begin
  487.     VolgaDBGrid := nil;
  488.     Close;
  489.   end;
  490. end;
  491.  
  492. function TVolgaDBGridColumnsEditor.GetEditState: TEditState;
  493. begin
  494.   Result := [];
  495.   if tbDeleteSelected.Enabled then Result := [esCanDelete];
  496. //  if tbDeleteSelected.Enabled then Result := [esCanDelete, esCanCut, esCanCopy];
  497. //  if ClipboardComponents then Include(Result, esCanPaste);
  498. end;
  499.  
  500. procedure TVolgaDBGridColumnsEditor.FormResize(Sender: TObject);
  501. begin
  502.   ListView1.Columns[0].Width := ListView1.ClientWidth;
  503. end;
  504.  
  505. procedure TVolgaDBGridColumnsEditor.miAddNewClick(Sender: TObject);
  506. begin
  507.   tbAddNewClick(Sender);
  508. end;
  509.  
  510. procedure TVolgaDBGridColumnsEditor.miDeleteSelectedClick(Sender: TObject);
  511. begin
  512.   tbDeleteSelectedClick(Sender);
  513. end;
  514.  
  515. procedure TVolgaDBGridColumnsEditor.miSelectAllClick(Sender: TObject);
  516. var i:Integer;
  517. begin
  518.   for i := 0 to ListView1.Items.Count - 1 do ListView1.Items[i].Selected := True;
  519. end;
  520.  
  521. procedure TVolgaDBGridColumnsEditor.miAddAllFieldsClick(Sender: TObject);
  522. begin
  523.   tbAddAllFieldsClick(Sender);
  524. end;
  525.  
  526. procedure TVolgaDBGridColumnsEditor.miRestoreDefaultsClick(Sender: TObject);
  527. begin
  528.   tbRestoreDefaultsClick(Sender);
  529. end;
  530.  
  531. procedure TVolgaDBGridColumnsEditor.tbDownClick(Sender: TObject);
  532. var
  533.   I, InsPos, sel: Integer;
  534. begin
  535.   if (ListView1.SelCount = 0) or (ListView1.SelCount > 1) then Exit;
  536.   InsPos := ListView1.Items.Count - 1;
  537.   sel := ListView1.Items.IndexOf(ListView1.Selected)+1;
  538.   while not ListView1.Items[InsPos].Selected do
  539.     Dec(InsPos);
  540.   if InsPos < (ListView1.Items.Count -1) then Inc(InsPos);
  541.   VolgaDBGrid.Columns.BeginUpdate;
  542.   try
  543.      for I := ListView1.Items.Count - 1 downto 0 do
  544.        if ListView1.Items[I].Selected then
  545.        begin
  546.          VolgaDBGrid.Columns.Items[I].Index := InsPos;
  547.          Dec(InsPos);
  548.        end;
  549.   finally
  550.     VolgaDBGrid.Columns.EndUpdate;
  551.   end;
  552.   Designer.Modified;
  553.   if (sel > ListView1.Items.Count - 1) then
  554.      ListView1.Items[ListView1.Items.Count-1].Selected := True
  555.   else
  556.      ListView1.Items[sel].Selected := True;
  557.   ListView1Change(nil,nil,ctState);
  558. end;
  559.  
  560. procedure TVolgaDBGridColumnsEditor.tbUpClick(Sender: TObject);
  561. var
  562.   I, InsPos, sel: Integer;
  563. begin
  564.   if (ListView1.SelCount = 0) or (ListView1.SelCount > 1) then Exit;
  565.   InsPos := 0;
  566.   sel := ListView1.Items.IndexOf(ListView1.Selected)-1;
  567.   while not ListView1.Items[InsPos].Selected do
  568.     Inc(InsPos);
  569.   if InsPos > 0 then Dec(InsPos);
  570.   VolgaDBGrid.Columns.BeginUpdate;
  571.   try
  572.      for I := 0 to ListView1.Items.Count - 1 do
  573.        if ListView1.Items[I].Selected then
  574.        begin
  575.          VolgaDBGrid.Columns.Items[I].Index := InsPos;
  576.          Inc(InsPos);
  577.        end;
  578.   finally
  579.     VolgaDBGrid.Columns.EndUpdate;
  580.   end;
  581.   Designer.Modified;
  582.   if (sel < 0) then
  583.      ListView1.Items[0].Selected := True
  584.   else
  585.      ListView1.Items[sel].Selected := True;
  586.   ListView1Change(nil,nil,ctState);
  587. end;
  588.  
  589. { TVolgaDBGridColumnsProperty }
  590.  
  591. procedure TVolgaDBGridColumnsProperty.Edit;
  592. begin
  593.   ShowItemsEditor(Designer, TVolgaDBGrid(GetComponent(0)));
  594. end;
  595.  
  596. function TVolgaDBGridColumnsProperty.GetAttributes: TPropertyAttributes;
  597. begin
  598.   Result := [paDialog, paReadOnly];
  599. end;
  600.  
  601. function TVolgaDBGridColumnsProperty.GetValue: string;
  602. begin
  603.   FmtStr(Result, '(%s)', [GetPropType^.Name]);
  604. end;
  605.  
  606.  
  607. { TVolgaDBGridEditor }
  608.  
  609. procedure TVolgaDBGridEditor.ExecuteVerb(Index: Integer);
  610. begin
  611.   case Index of
  612.     0: ShowItemsEditor(Designer, TVolgaDBGrid(Component));
  613.   end;
  614. end;
  615.  
  616. function TVolgaDBGridEditor.GetVerb(Index: Integer): string;
  617. begin
  618.   case Index of
  619.     0: Result := 'Columns Editor ...';
  620.   end;
  621. end;
  622.  
  623. function TVolgaDBGridEditor.GetVerbCount: Integer;
  624. begin
  625.   Result := 1;
  626. end;
  627.  
  628. { TVolgaColumnDataFieldProperty }
  629.  
  630. function TVolgaColumnDataFieldProperty.GetAttributes: TPropertyAttributes;
  631. begin
  632.   Result := [paValueList, paSortList, paMultiSelect];
  633. end;
  634.  
  635. procedure TVolgaColumnDataFieldProperty.GetValueList(List: TStrings);
  636. var
  637.   Grid: TVolgaCustomDBGrid;
  638.   DataSource: TDataSource;
  639. begin
  640.   Grid := (GetComponent(0) as TVolgaColumn).Grid;
  641.   if (Grid = nil) then Exit;
  642.   DataSource := Grid.DataSource;
  643.   if (DataSource <> nil) and (DataSource.DataSet <> nil)
  644.   and (DataSource.DataSet.FieldCount > 0) then
  645.     DataSource.DataSet.GetFieldNames(List);
  646. end;
  647.  
  648. procedure TVolgaColumnDataFieldProperty.GetValues(Proc: TGetStrProc);
  649. var
  650.   I: Integer;
  651.   Values: TStringList;
  652. begin
  653.   Values := TStringList.Create;
  654.   try
  655.     GetValueList(Values);
  656.     for I := 0 to Values.Count - 1 do
  657.       Proc(Values[I]);
  658.   finally
  659.     Values.Free;
  660.   end;
  661. end;
  662.  
  663. { TVolgaColumnLookupKeyProperty }
  664.  
  665. procedure TVolgaColumnLookupKeyProperty.GetValueList(List: TStrings);
  666. var
  667.   Column: TVolgaColumn;
  668. begin
  669.   Column := GetComponent(0) as TVolgaColumn;
  670.   if (Column = nil) then Exit;
  671.   if (Column.LookupDataSet <> nil) and (Column.LookupDataSet.FieldCount>0) then
  672.     Column.LookupDataSet.GetFieldNames(List);
  673. end;
  674.  
  675. function TVolgaColumnLookupKeyProperty.GetAttributes: TPropertyAttributes;
  676. begin
  677.   Result := [paValueList, paSortList, paMultiSelect];
  678. end;
  679.  
  680. procedure TVolgaColumnLookupKeyProperty.GetValues(Proc: TGetStrProc);
  681. var
  682.   I: Integer;
  683.   Values: TStringList;
  684. begin
  685.   Values := TStringList.Create;
  686.   try
  687.     GetValueList(Values);
  688.     for I := 0 to Values.Count - 1 do
  689.       Proc(Values[I]);
  690.   finally
  691.     Values.Free;
  692.   end;
  693. end;
  694.  
  695. end.
  696.