• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 555
  • Last Modified:

ListView

Hi All

My question is :

I am having a listview statring with 5 columns and I am filling it from a table or a query.During runtime I might Add new columns and i want to fill that specific columns with it's assigned data from the table without refilling the entire listview.
please anyone got a solution.

one more thing, what is the way to save a user layout for a listview , so each user can use his own layout for the columns in the listview

best regards

0
ibrobar
Asked:
ibrobar
  • 7
  • 5
1 Solution
 
Amir AzhdariCommented:
Hi,
you can use a dynamic array of TlistView and create it in runtime something like to this:

var ListName:array of TlistView;

begin
   SetLength(ListName,10);
end;
0
 
2266180Commented:
that is not enough as setlength will only create the array but not initialize the listviews.

you will also have to
var ListName:array of TlistView;

begin
   SetLength(ListName,10);
  for i:=0 to length(listname0 do
    listname[i]:=TListView.Create(this);// for the current form
end;
0
 
2266180Commented:
hm .. that should teach me to read the question first. so sorry for the above anwser but that is NOT what you want.
you will only have to do something like this:

var l:TlistView; c:TListColumn; i:TCollectionItem;
begin
  c:=l.Columns.Add;
  c.Caption:='column name';
  for all rows to add do
  begin
    i:=c.Collection.Add;
    i.DisplayName:='value';
  end;
end;
0
Industry Leaders: 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!

 
2266180Commented:
regarding your second question:
you wil lhave to save yourself all data:
- listview sizes
- iterate through all columns and
--- save widths/other data
--- iterate through collection ffrom each column and
------- save all sizes/other data
0
 
ibrobarAuthor Commented:
thanks ciuly

can i get a DBlistview source code for delphi4 if you have it

regards
0
 
2266180Commented:
firstly, we cannot give out source code from delphi packages for obvious reasons. if I remember correctly, someone on another topic was working with you on something similiar, is it not?
secondly, your request is kind of off-topic :) and you already have a question open on this matter so you should find a solution there.
0
 
ibrobarAuthor Commented:
YES CIULY

you are right but the person i was working with wasn't able to give me the correct solution , besides that DBListView is not Borland code so we cann't fear copyright here it's a development tool.

thanks any way
0
 
2266180Commented:
actually we can fear copyright issues as the code should have some copyright or EULA or whatever. but unless you say which one you talk about, I cannot be sure.

but you are missing the point with that question and that is that you did not say which component you are looking for. there are a TON of DBListView compnents out there. you have to choose one.
OR, if you have one, you must give us information or link to it so that we can see what is the issue with it. we cannot help you unless you help us first by giving the info requested. let's move this discussion to that other thread (http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21857751.html) for clarification.
also, we can discuss there why this solution (http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21857008.html) doesn't work for you since you already accepted it.

cheers
0
 
ibrobarAuthor Commented:
Hi i tried this code

var l:TlistView; c:TListColumn; i:TCollectionItem;
begin
  c:=l.Columns.Add;
  c.Caption:='column name';
  for all rows to add do
  begin
    i:=c.Collection.Add;
    i.DisplayName:='value';
  end;
end;

but it didn't work .

regards
0
 
2266180Commented:
don't tell me you run that piece of code just the way it is... it was just a sketch, I hope that was obvious. if not for other reason then for the syntactical errors at compilation time.
if you did implement real code based on the sketh you should post it and also metnion what and where is the error so we can help you ;)
0
 
ibrobarAuthor Commented:
Hi Ciuly

Afcourse i didn't use the code as it is . But let me just ask you about the loop:  For I:=0 to listview1.items.count-1 do it it right


thanks

regards
0
 
2266180Commented:
that depends how you use the counter in respect to the vector.
you can use
for i:=2 to listview1.items.count+1 with no problem. you just have to make sure that the index will alwas be 0-based
so
for i:=0 to listview1.items.count-1 do
  use listview1.items[i]
for i:=1 to listview1.items.count do
  use listview1.items[i-1]
for i:=2 to listview1.items.count+1 do
  use listview1.items[i-2]
all 3 are equivalent and will work correctly.

anyway, since it's weekedn, i'm at home and also have access to my delphi environment, so I started up a project to see exactly what your issue looks like, and of course saw the issue right away.
I must tell you that I never used a vsreport style of the listview so I didn't know about the "columns" property. I just assumed that the firt items will be the columns.

oh well, sorry for the mixup. here is a small test code that does what you want, provided that you are using the vsreport style of the listview

dfm follows:

object Form1: TForm1
  Left = 192
  Top = 114
  Width = 575
  Height = 327
  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 = 16
    Top = 16
    Width = 449
    Height = 265
    Columns = <
      item
        Caption = 'column1'
      end
      item
        Caption = 'column2'
      end
      item
        Caption = 'column3'
      end
      item
        Caption = 'column4'
      end
      item
        Caption = 'column5'
      end>
    GridLines = True
    Items.Data = {
      CE0000000300000000000000FFFFFFFFFFFFFFFF050000000000000005726F77
      303005726F77303105726F77303205726F77303305726F77303405726F773035
      00000000FFFFFFFFFFFFFFFF050000000000000005726F77313005726F773131
      05726F77313205726F77313305726F77313405726F77313500000000FFFFFFFF
      FFFFFFFF050000000000000005726F77323005726F77323105726F7732320572
      6F77323305726F77323405726F773235FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
      FFFFFFFFFFFFFFFFFFFFFFFFFFFF}
    MultiSelect = True
    RowSelect = True
    TabOrder = 0
    ViewStyle = vsReport
  end
  object Button1: TButton
    Left = 480
    Top = 24
    Width = 75
    Height = 25
    Caption = 'add col'
    TabOrder = 1
    OnClick = Button1Click
  end
end


unit follows:

unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var c:tlistcolumn; i:integer;
begin
  c:=listview1.columns.add;
  c.Caption:='Column'+inttostr(listview1.columns.Count);
  for i:=1 to listview1.Items.Count do
    listview1.Items[i-1].SubItems.add('row'+inttostr(i-1)+inttostr(listview1.columns.Count));
end;

end.
0
 
ibrobarAuthor Commented:
I will try it today

thanks
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now