Changeset 463 for Common/UListViewSort.pas
- Timestamp:
- Feb 10, 2014, 5:18:38 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/UListViewSort.pas
r432 r463 9 9 uses 10 10 {$IFDEF Windows}Windows, CommCtrl, {$ENDIF}Classes, Graphics, ComCtrls, SysUtils, 11 Controls, DateUtils, Dialogs, SpecializedList ;11 Controls, DateUtils, Dialogs, SpecializedList, Forms, Grids, StdCtrls, ExtCtrls; 12 12 13 13 type … … 19 19 TListFilterEvent = procedure (ListViewSort: TListViewSort) of object; 20 20 21 TListViewSort = class 21 TListViewSort = class(TComponent) 22 22 private 23 23 FListView: TListView; … … 43 43 List: TListObject; 44 44 Source: TListObject; 45 constructor Create ;45 constructor Create(AOwner: TComponent); override; 46 46 destructor Destroy; override; 47 47 function CompareTime(Time1, Time2: TDateTime): Integer; … … 50 50 function CompareBoolean(Value1, Value2: Boolean): Integer; 51 51 procedure Refresh; 52 published 52 53 property ListView: TListView read FListView write SetListView; 53 54 property OnCompareItem: TCompareEvent read FOnCompareItem … … 61 62 end; 62 63 64 { TListViewFilter } 65 66 TListViewFilter = class(TWinControl) 67 private 68 FOnChange: TNotifyEvent; 69 FStringGrid1: TStringGrid; 70 procedure DoOnKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); 71 public 72 constructor Create(AOwner: TComponent); override; 73 procedure UpdateFromListView(ListView: TListView); 74 function TextEntered: Boolean; 75 function GetColValue(Index: Integer): string; 76 property StringGrid: TStringGrid read FStringGrid1 write FStringGrid1; 77 published 78 property OnChange: TNotifyEvent read FOnChange write FOnChange; 79 property Align; 80 property Anchors; 81 end; 82 83 procedure Register; 84 85 63 86 implementation 87 88 procedure Register; 89 begin 90 RegisterComponents('Common', [TListViewSort, TListViewFilter]); 91 end; 92 93 { TListViewFilter } 94 95 procedure TListViewFilter.DoOnKeyUp(Sender: TObject; var Key: Word; 96 Shift: TShiftState); 97 begin 98 if Assigned(FOnChange) then 99 FOnChange(Self); 100 end; 101 102 constructor TListViewFilter.Create(AOwner: TComponent); 103 begin 104 inherited Create(AOwner); 105 FStringGrid1 := TStringGrid.Create(Self); 106 FStringGrid1.Align := alClient; 107 FStringGrid1.Parent := Self; 108 FStringGrid1.Visible := True; 109 FStringGrid1.ScrollBars := ssNone; 110 FStringGrid1.FixedCols := 0; 111 FStringGrid1.FixedRows := 0; 112 FStringGrid1.RowCount := 1; 113 FStringGrid1.Options := [goFixedHorzLine, goFixedVertLine, goVertLine, 114 goHorzLine, goRangeSelect, goEditing, goAlwaysShowEditor, goSmoothScroll]; 115 FStringGrid1.OnKeyUp := DoOnKeyUp; 116 end; 117 118 procedure TListViewFilter.UpdateFromListView(ListView: TListView); 119 var 120 I: Integer; 121 NewColumn: TGridColumn; 122 begin 123 with FStringGrid1 do begin 124 Columns.Clear; 125 while Columns.Count > ListView.Columns.Count do Columns.Delete(Columns.Count - 1); 126 while Columns.Count < ListView.Columns.Count do NewColumn := Columns.Add; 127 for I := 0 to ListView.Columns.Count - 1 do begin 128 Columns[I].Width := ListView.Columns[I].Width; 129 end; 130 end; 131 end; 132 133 function TListViewFilter.TextEntered: Boolean; 134 var 135 I: Integer; 136 begin 137 Result := False; 138 for I := 0 to FStringGrid1.ColCount - 1 do begin 139 if FStringGrid1.Cells[I, 0] <> '' then begin 140 Result := True; 141 Break; 142 end; 143 end; 144 end; 145 146 function TListViewFilter.GetColValue(Index: Integer): string; 147 begin 148 if (Index >= 0) and (Index < StringGrid.Columns.Count) then 149 Result := StringGrid.Cells[Index, 0] 150 else Result := ''; 151 end; 64 152 65 153 { TListViewSort } … … 160 248 end; 161 249 162 constructor TListViewSort.Create; 163 begin 250 constructor TListViewSort.Create(AOwner: TComponent); 251 begin 252 inherited; 164 253 List := TListObject.Create; 165 254 List.OwnsObjects := False;
Note:
See TracChangeset
for help on using the changeset viewer.