[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Making all columns visible in Delphi Grid

Posted on 2011-04-27
6
Medium Priority
?
1,474 Views
Last Modified: 2012-05-11
Hi everyone.

I'm trying to program a quick way to make all of the columns in a grid visible, rather than the user having to individually click each of the checkboxes in the ColumnsQuickCustomization drop down. I know this can be done by individually calling each of the columns, but I would like to find a way around this since many of the grids have quite a large number of columns--plus I would be able to drop it into any grid with relatively little coding. I was thinking something along the lines of:

if TcxGrid.ColumnProperty.Visible := False then TcxGrid.ColumnProperty.Visible := True;

Would this be possible, or am I going about this the wrong way?
0
Comment
Question by:Bianca
  • 2
  • 2
5 Comments
 
LVL 38

Accepted Solution

by:
Geert Gruwez earned 500 total points
ID: 35480954
you could use a popupmenu alongside the cxGridMenu to do that:
pas
 
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
  cxStyles, cxCustomData, cxFilter, cxData, cxDataStorage, cxEdit, Menus,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridCustomTableView,
  cxGridTableView, cxGridCustomView, cxClasses, cxGridLevel, cxGrid;

type
  TForm1 = class(TForm)
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGrid1TableView1: TcxGridTableView;
    cxGrid1TableView1Column1: TcxGridColumn;
    cxGrid1TableView1Column2: TcxGridColumn;
    cxGrid1TableView1Column3: TcxGridColumn;
    cxGrid1TableView1Column4: TcxGridColumn;
    cxGrid1TableView1Column5: TcxGridColumn;
    cxGrid1TableView1Column6: TcxGridColumn;
    cxGrid1TableView1Column7: TcxGridColumn;
    cxGridPopupMenu1: TcxGridPopupMenu;
    PopupMenu1: TPopupMenu;
    Showallcolumns1: TMenuItem;
    Hideallcolumns1: TMenuItem;
    procedure Showallcolumns1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Showallcolumns1Click(Sender: TObject);
var vw: TcxCustomGridView;
  I: Integer;
begin
  vw := cxGridPopupMenu1.Grid.ActiveView;
  for I := 0 to vw.DataController.ItemCount - 1 do
    TcxGridColumn(vw.DataController.GetItem(I)).Visible := TComponent(Sender).Tag = 1;
end;

end.

Open in new window


dfm
 
object Form1: TForm1
  Left = 245
  Top = 86
  Caption = 'Form1'
  ClientHeight = 525
  ClientWidth = 963
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object cxGrid1: TcxGrid
    Left = 88
    Top = 72
    Width = 713
    Height = 353
    TabOrder = 0
    object cxGrid1TableView1: TcxGridTableView
      NavigatorButtons.ConfirmDelete = False
      DataController.Summary.DefaultGroupSummaryItems = <>
      DataController.Summary.FooterSummaryItems = <>
      DataController.Summary.SummaryGroups = <>
      object cxGrid1TableView1Column1: TcxGridColumn
        Caption = 'A'
      end
      object cxGrid1TableView1Column2: TcxGridColumn
        Caption = 'B'
      end
      object cxGrid1TableView1Column3: TcxGridColumn
        Caption = 'C'
      end
      object cxGrid1TableView1Column4: TcxGridColumn
        Caption = 'D'
      end
      object cxGrid1TableView1Column5: TcxGridColumn
        Caption = 'E'
      end
      object cxGrid1TableView1Column6: TcxGridColumn
        Caption = 'F'
      end
      object cxGrid1TableView1Column7: TcxGridColumn
        Caption = 'G'
      end
    end
    object cxGrid1Level1: TcxGridLevel
      GridView = cxGrid1TableView1
    end
  end
  object cxGridPopupMenu1: TcxGridPopupMenu
    Grid = cxGrid1
    PopupMenus = <
      item
        GridView = cxGrid1TableView1
        HitTypes = [gvhtColumnHeader]
        Index = 0
        PopupMenu = PopupMenu1
      end>
    Left = 40
    Top = 200
  end
  object PopupMenu1: TPopupMenu
    Left = 40
    Top = 256
    object Showallcolumns1: TMenuItem
      Tag = 1
      Caption = 'Show all columns'
      OnClick = Showallcolumns1Click
    end
    object Hideallcolumns1: TMenuItem
      Caption = 'Hide all columns'
      OnClick = Showallcolumns1Click
    end
  end
end

Open in new window

0
 
LVL 4

Assisted Solution

by:fromer
fromer earned 500 total points
ID: 35481494
Here is TcxGridTableView = class(TcxCustomGridTableView)

which has a property:

property Columns[Index: Integer]: TcxGridColumn read GetColumn write SetColumn;

and it's GetColumn method is

function TcxGridTableView.GetColumn(Index: Integer): TcxGridColumn;
begin
  Result := TcxGridColumn(Items[Index]);
end;

Items property is inherited from TcxCustomGridTableView, and it's declared as

property Items[Index: Integer]: TcxCustomGridTableItem read GetItem write SetItem;



So I will suggest functions like below...
//------------------------------------------------------------------------------------------------------
function TryMakeAllColumnsVisible(_View :  TcxCustomGridView) : Boolean; forward;
//------------------------------------------------------------------------------------------------------
procedure MakeAllColumnsVisible(_Grid : TcxGrid); overload;
var
  k : Integer;
begin
  for k := 0 to _Grid.ViewCount - 1 do
  begin
    TryMakeAllColumnsVisible(_Grid.Views[k]);
  end;
end;
//------------------------------------------------------------------------------------------------------
procedure MakeAllColumnsVisible(_View : TcxCustomGridTableView); overload;
var
  k : Integer;
begin
  for k := 0 to _View.ItemCount - 1 do
  begin
    _View.Items[k].Visible := True;
  end;
end;
//------------------------------------------------------------------------------------------------------
function TryMakeAllColumnsVisible(_View :  TcxCustomGridView) : Boolean;
begin
  if _View is TcxCustomGridTableView then
  begin
    MakeAllColumnsVisible(TcxCustomGridTableView(_View));
    Result := True;
  end
  else
  begin
    Result := False;
  end;
end;
//------------------------------------------------------------------------------------------------------
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 35483354
nice fromer,
but a little complex ... no ?

is this part of a larger piece of code ?
0
 
LVL 4

Expert Comment

by:fromer
ID: 35483411
I can see the
unit cxGrid,
unit cxGridCustomTableView,
etc...

The codes after "So I will suggest functions like below..." are written by me..
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 35859749
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question