[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

listview columns layout / save layout and load it as well

Posted on 2004-03-22
10
Medium Priority
?
421 Views
Last Modified: 2010-04-05
Hi Experts

I have a listview with 6 static columns.
I want to add dynamic columns during runtime and then to save the new layout as the user name and then to call it again by clicking on the user name. so what i need is to customize the listview up to each user using the application

hope i made my self clear.

one more thing how can i export the listview items to an excel and vice versa

thanks all in advance
0
Comment
Question by:ibrobar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
10 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 10652432
Hi
For Excel automation look there
http://www.djpate.freeserve.co.uk/AutoExcl.htm
0
 
LVL 17

Expert Comment

by:mokule
ID: 10652460
Store appropriate parameters in an INI file. For example sections for each user.
TIniFile
0
 

Expert Comment

by:rafamvc
ID: 10652658
"I want to add dynamic columns during runtime"

ListView1.Columns.Add;

" and then to save the new layout as the user name"
save to a file? db?

Maybe this help:
procedure TForm1.Button1Click(Sender: TObject);
var i,j: Integer;
    TempColumn : TListColumn;
begin
   //TempColumn := ListView1.Columns.Add;
   //TempColumn.Caption := 'New Column';
   //ListView1.Columns.Count;
   for i:=0 to ListView1.Columns.Count -1 do
   begin
     //Save where you want the columns captions
     ShowMessage(ListView1.Column[i].Caption);
   end;
   for i:=0 to ListView1.Items.Count -1 do
   begin
     ShowMessage(ListView1.Items.Item[i].Caption);
     for j:=0 to ListView1.Columns.Count -2 do
     //Caution: -2 because first column is the item itself
        ShowMessage(ListView1.Items.Item[i].SubItems[j]);
   end;
end;

"and then to call it again by clicking on the user name."
Explain a little more about where you will save and then we make the second part

" so what i need is to customize the listview up to each user using the application"
ok.

[]´s
Rafael Cardoso - Brazil
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Expert Comment

by:rafamvc
ID: 10652672
  //TempColumn := ListView1.Columns.Add;
   //TempColumn.Caption := 'New Column';
   //ListView1.Columns.Count;

ops forgot to explain:

this 3 lines set up new column.
0
 
LVL 23

Accepted Solution

by:
Ferruccio Accalai earned 500 total points
ID: 10652777
Ok my version:

To save and reload the listviews you could use the readcomponent and writecomponent procedures that are really useful...

To export to excel create a oleobject and fill it reading the listview

my example as follows:

{unit1.pas}

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls,comobj;

type
  TForm1 = class(TForm)
    ListView1: TListView;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  MemStr : TMemoryStream;
begin
  MemStr := TMemoryStream.Create;
  try
    {if you need to save just the structure without the content simply add
    ListView1.Items.Clear}
    MemStr.WriteComponent(ListView1);
    memSTr.SaveToFile('c:\ThisUserListView.dat');
  finally
    MemStr.Free;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
MemStr : TMemoryStream;
begin
MemStr:= TMemoryStream.Create;
  try
    MemStr.LoadFromFile('c:\ThisUserListView.dat');
    MemStr.ReadComponent(ListView1);
  finally
    MemStr.Free;
  end;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
Excel: Variant;
row,col:Integer;
begin
  try
    excel:=CreateOleObject('Excel.Application');
  except
    ShowMEssage('Excel not available');
    exit;
  end;
    excel.Visible:=False;
    Row:=1;
    excel.Workbooks.Add;
    for Col := 0 to ListView1.Columns.Count-1 do begin
      excel.Cells[row,Col + 1].Value:= ListView1.Columns.Items[col].Caption;
      excel.cells[row,Col+1].ColumnWidth := ListView1.Columns.Items[col].Width/5;
      end;
    try
    for row := 2 to ListView1.items.count+1 do
      for Col := 0 to ListView1.Columns.Count-1 do begin
        If Col = 0 then
          excel.Cells[row,Col + 1].Value:= (ListView1.Items[Row-2].caption)
        else
          excel.Cells[row,Col + 1].Value:= (ListView1.Items[Row-2].subitems[col-1]);
    end;
    Except
         MessageBox(0,'Warning, there was an error during the operation. Exportation aborted.','',0);
         excel.quit;
    end;
    excel.visible := true;
    excel := Unassigned;
end;

end.

{Unit1.dfm}

object Form1: TForm1
  Left = 192
  Top = 107
  Width = 507
  Height = 291
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object ListView1: TListView
    Left = 130
    Top = 72
    Width = 250
    Height = 150
    Columns = <
      item
        Caption = 'Title1'
      end
      item
        Caption = 'Title2'
      end
      item
        Caption = 'Title3'
      end
      item
        Caption = 'Title4'
      end>
    Items.Data = {
      910000000400000000000000FFFFFFFFFFFFFFFF030000000000000001310132
      0133013400000000FFFFFFFFFFFFFFFF03000000000000000132013501360137
      00000000FFFFFFFFFFFFFFFF0300000000000000013301380139023130000000
      00FFFFFFFFFFFFFFFF03000000000000000134013101320133FFFFFFFFFFFFFF
      FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF}
    TabOrder = 0
    ViewStyle = vsReport
  end
  object Button1: TButton
    Left = 138
    Top = 20
    Width = 75
    Height = 25
    Caption = 'Save List'
    TabOrder = 1
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 292
    Top = 20
    Width = 75
    Height = 25
    Caption = 'Load List'
    TabOrder = 2
    OnClick = Button2Click
  end
  object Button3: TButton
    Left = 390
    Top = 194
    Width = 75
    Height = 25
    Caption = 'To Excel'
    TabOrder = 3
    OnClick = Button3Click
  end
end
0
 

Expert Comment

by:rafamvc
ID: 10652907
wow, realy nice your code! ;) Solved another problem of mine ;)
tnks Ferruccio68!
[]´s
Rafael Cardoso
0
 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 10652935
Rafael, just for curiosity: what was your problem? About the excel export or the component streaming? :)))
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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

650 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