Listview question - export to file


how can i export listview values to file and read it back into listview?
saint10Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
kretzschmarConnect With a Mentor Commented:
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
 
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
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
All Courses

From novice to tech pro — start learning today.