Listview question - export to file


how can i export listview values to file and read it back into listview?
saint10Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JaymolCommented:
Hi.  I'm afraid there is no quick and easy way to do this.  You've gotta do it yourself, cell by cell.

If you need an example, let me know, but it's pretty straight forward stuff.

Ta,

John.
0
saint10Author Commented:
yes please , i need an example thanks!!!
0
kretzschmarCommented:
hi saint10,

you can write and read the values (and a bit more) by using the delphi streaming-system like

//write Listview
procedure TForm1.Button1Click(Sender: TObject);
var FS : TFileStream;
begin
  FS := TFileStream.Create('C:\LV.Dat',fmCreate);
  FS.WriteComponent(ListView1);
  FS.Free;
end;

//Read Listview
procedure TForm1.Button2Click(Sender: TObject);
var FS : TFileStream;
begin
  RegisterClass(TListView);
  FS := TFileStream.Create('C:\LV.Dat',fmOpenRead);
  TComponent(ListView1) := FS.ReadComponent(ListView1);
  FS.Free;
end;

meikl
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

saint10Author Commented:
How can i move item up and down, let's say i have 10 items and the item number 9 i want to move it up to 1 or ?

0
saint10Author Commented:
and another one quesion, when i save all values in listview into file and load it bback, the checkbbox values will not ccome
0
saint10Author Commented:
How can i move item up and down, let's say i have 10 items and the item number 9 i want to move it up to 1 or ?

0
saint10Author Commented:
if you have any example for me about the listview,

e.g how can i move items up and down "itemindex"

then email me at

saint10@vis.is
0
kretzschmarCommented:
hi saint10,

thanks for accepting ;-)

to methods how to swap/move items

procedure SwapItem(List : TListView; Index1, Index2 : Integer);
var TmpItem : TListItem;
begin
  If (Index1 < List.Items.Count - 1) and
     (Index2 < List.Items.Count - 1) and
     (Index1 > 0) and
     (Index2 > 0) and
     (Index1 <> Index2) then
  begin
    TmpItem := List.Items.Add;
    TmpItem.Assign(List.Items[Index1]);
    List.Items[Index1].Assign(List.Items[Index2]);
    List.Items[Index2].Assign(TmpItem);
    TmpItem.Delete;
  end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  SwapItem(Listview1,2,5);
end;

procedure MoveItem(List : TListView; Index1, Index2 : Integer);
var TmpItem : TListItem;
begin
  If (Index1 < List.Items.Count - 1) and
     (Index2 < List.Items.Count - 1) and
     (Index1 > 0) and
     (Index2 > 0) and
     (Index1 < Index2) then
  begin
    TmpItem := List.Items.Insert(Index1);
    TmpItem.Assign(List.Items[Index2+1]);
    List.Items[Index2+1].Delete;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  MoveItem(ListView1,2,5);
end;


meikl
0
saint10Author Commented:
Thanks 'kretzschmar'

just one more, how can i know itemindex and set it to variable?
0
kretzschmarCommented:
? explain more
0
saint10Author Commented:
this works not very well,

let's say if i have 10 items in the listview and i press any of the 10 item, let's say number 3 and i like to move it to 10 with seven buttons click, how can i do that?
0
kretzschmarCommented:
hi again,

some changes in the moveprocedure,
to perform laso a moveup

procedure MoveItem(List : TListView; Index1, Index2 : Integer; DoSelect : Boolean);
var TmpItem : TListItem;
begin
  If (Index1 < List.Items.Count) and
     (Index2 < List.Items.Count) and
     (Index1 > -1) and
     (Index2 > -1) and
     (Index1 < Index2) then
  begin
    TmpItem := List.Items.Insert(Index1);
    TmpItem.Assign(List.Items[Index2+1]);
    List.Items[Index2+1].Delete;
    If DoSelect then List.Selected := TmpItem;
  end;
end;


//Move Down
procedure TForm1.Button3Click(Sender: TObject);
begin
  MoveItem(ListView1,ListView1.Selected.Index,ListView1.Selected.Index + 1,False);
end;

//Move up
procedure TForm1.Button4Click(Sender: TObject);
begin
  MoveItem(ListView1,ListView1.Selected.Index-1,ListView1.Selected.Index,True );
end;

meikl
0
saint10Author Commented:
no!!!

this is not so good, i can't select the first item and move it down  
and i can't select the bottom item and move it to to top

what's wrong?
0
kretzschmarCommented:
hi saint10,

did you replaced the procedure moveitem with the latest in my last comment?

meikl
0
saint10Author Commented:
Sorry!!!

this works very well, you are the man today

Thanks
0
kretzschmarCommented:
;-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.