From 0af501a361f693011ba7edf51736b3a00f493587 Mon Sep 17 00:00:00 2001 From: alexs75 Date: Mon, 28 Jul 2014 10:24:14 +0000 Subject: [PATCH] TRxColumn.Option - enable show/hide column from grid column dialog git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3391 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/rx/trunk/rxdbgrid.pas | 21 ++++++++------ components/rx/trunk/rxdbgrid_columsunit.lfm | 3 +- components/rx/trunk/rxdbgrid_columsunit.pas | 32 +++++++++++++++++---- 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/components/rx/trunk/rxdbgrid.pas b/components/rx/trunk/rxdbgrid.pas index 55f672d8f..c900b9a8c 100644 --- a/components/rx/trunk/rxdbgrid.pas +++ b/components/rx/trunk/rxdbgrid.pas @@ -74,6 +74,9 @@ type //TRxDBGridAllowedOperations = set of TRxDBGridAllowedOperation; {$ENDIF} + TRxColumnOption = (coCustomizeVisible, coCustomizeWidth); + TRxColumnOptions = set of TRxColumnOption; + TRxColumnEditButtonStyle = (ebsDropDownRx, ebsEllipsisRx, ebsGlyphRx, ebsUpDownRx, ebsPlusRx, ebsMinusRx); @@ -417,6 +420,7 @@ type FKeyList: TStrings; FNotInKeyListIndex: integer; FOnDrawColumnCell: TDrawColumnCellEvent; + FOptions: TRxColumnOptions; FSortFields: string; FSortOrder: TSortMarker; FSortPosition: integer; @@ -443,18 +447,18 @@ type property SortOrder: TSortMarker read FSortOrder write FSortOrder; property SortPosition: integer read FSortPosition; published - property SortFields: string read FSortFields write FSortFields; - property Footer: TRxColumnFooter read GetFooter write SetFooter; property Constraints:TRxDBGridCollumnConstraints read GetConstraints write SetConstraints; - property ImageList: TImageList read FImageList write SetImageList; - property KeyList: TStrings read GetKeyList write SetKeyList; - property NotInKeyListIndex: integer read FNotInKeyListIndex - write SetNotInKeyListIndex default -1; - property Filter: TRxColumnFilter read FFilter write SetFilter; property DirectInput : boolean read FDirectInput write FDirectInput default true; property EditButtons:TRxColumnEditButtons read FEditButtons write SetEditButtons; - property OnDrawColumnCell: TDrawColumnCellEvent read FOnDrawColumnCell write FOnDrawColumnCell; + property Filter: TRxColumnFilter read FFilter write SetFilter; + property Footer: TRxColumnFooter read GetFooter write SetFooter; + property ImageList: TImageList read FImageList write SetImageList; + property KeyList: TStrings read GetKeyList write SetKeyList; + property NotInKeyListIndex: integer read FNotInKeyListIndex write SetNotInKeyListIndex default -1; + property Options:TRxColumnOptions read FOptions write FOptions default [coCustomizeVisible, coCustomizeWidth]; + property SortFields: string read FSortFields write FSortFields; property WordWrap:boolean read FWordWrap write SetWordWrap default false; + property OnDrawColumnCell: TDrawColumnCellEvent read FOnDrawColumnCell write FOnDrawColumnCell; end; { TRxDbGridColumns } @@ -5164,6 +5168,7 @@ begin FFilter := TRxColumnFilter.Create(Self); FDirectInput := true; FEditButtons:=TRxColumnEditButtons.Create(Self); + FOptions:=[coCustomizeVisible, coCustomizeWidth]; end; destructor TRxColumn.Destroy; diff --git a/components/rx/trunk/rxdbgrid_columsunit.lfm b/components/rx/trunk/rxdbgrid_columsunit.lfm index 209e3448d..f6e226ff2 100644 --- a/components/rx/trunk/rxdbgrid_columsunit.lfm +++ b/components/rx/trunk/rxdbgrid_columsunit.lfm @@ -126,7 +126,7 @@ object rxDBGridColumsForm: TrxDBGridColumsForm end object btnApply: TBitBtn AnchorSideBottom.Side = asrBottom - Left = -63 + Left = -205 Height = 30 Top = 0 Width = 71 @@ -173,6 +173,7 @@ object rxDBGridColumsForm: TrxDBGridColumsForm Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goEditing, goRowSelect, goRowHighlight] TabOrder = 1 TitleStyle = tsNative + OnClick = StringGrid1Click OnValidateEntry = StringGrid1ValidateEntry ColWidths = ( 30 diff --git a/components/rx/trunk/rxdbgrid_columsunit.pas b/components/rx/trunk/rxdbgrid_columsunit.pas index b7f54116b..d5f383818 100644 --- a/components/rx/trunk/rxdbgrid_columsunit.pas +++ b/components/rx/trunk/rxdbgrid_columsunit.pas @@ -53,6 +53,7 @@ type procedure FormCreate(Sender: TObject); procedure sbUpClick(Sender: TObject); procedure sbDownClick(Sender: TObject); + procedure StringGrid1Click(Sender: TObject); procedure StringGrid1ValidateEntry(sender: TObject; aCol, aRow: Integer; const OldValue: string; var NewValue: String); private @@ -159,6 +160,21 @@ begin end; end; +procedure TrxDBGridColumsForm.StringGrid1Click(Sender: TObject); +var + i:integer; + C:TRxColumn; +begin + i:=StringGrid1.Row; + + C:=FGrid.ColumnByCaption(StringGrid1.Cells[1, i]); + if coCustomizeVisible in C.Options then + StringGrid1.Options:=StringGrid1.Options + [goEditing] + else + StringGrid1.Options:=StringGrid1.Options - [goEditing] + ; +end; + procedure TrxDBGridColumsForm.StringGrid1ValidateEntry(sender: TObject; aCol, aRow: Integer; const OldValue: string; var NewValue: String); begin @@ -169,20 +185,24 @@ end; procedure TrxDBGridColumsForm.SetGrid(AGrid: TRxDBGrid); var i:integer; + C:TRxColumn; begin if AGrid=FGrid then exit; FGrid:=AGrid; if Assigned(AGrid) then begin - StringGrid1.RowCount:=AGrid.Columns.Count+1; + StringGrid1.RowCount:=AGrid.Columns.Count + 1; + for i:=0 to AGrid.Columns.Count-1 do begin - StringGrid1.Cells[0, i+1]:=BoolToStr(AGrid.Columns[i].Visible, '1', '0'); - StringGrid1.Cells[1, i+1]:=AGrid.Columns[i].Title.Caption; - if AGrid.Columns[i].Width = 0 then - StringGrid1.Cells[2, i+1]:=IntToStr(AGrid.DefaultColWidth) + C:=AGrid.Columns[i] as TRxColumn; + + StringGrid1.Cells[0, i + 1]:=BoolToStr(C.Visible, '1', '0'); + StringGrid1.Cells[1, i + 1]:=C.Title.Caption; + if C.Width = 0 then + StringGrid1.Cells[2, i + 1]:=IntToStr(AGrid.DefaultColWidth) else - StringGrid1.Cells[2, i+1]:=IntToStr(AGrid.Columns[i].Width); + StringGrid1.Cells[2, i + 1]:=IntToStr(C.Width); end; end else