Solved

Listview Loop Problem (Urgent)

Posted on 2004-04-02
23
224 Views
Last Modified: 2010-04-05
Hi there,

I have the following problem.
I have a listview that imports a list.
What i want to do is to have a loop that will scroll the lists 1 by 1, execute something and then go to the next one in the list etc... until the listbox is empty.

My code is here but it does not work :(

procedure TOBJ_MainForm.LMDButton2Click(Sender: TObject);
var
I: Integer;

Begin

for I:= 0 to ListView1.Items.Count -1  do
begin
 

    ID.Text:=( ListView1.Items[I].Caption);
    Edit9.Text:=( ListView1.Items[I].SubItems[0]);
    Edit10.Text:=( ListView1.Items[I].SubItems[1]);
    Edit11.Text:=( ListView1.Items[I].SubItems[2]);
    Edit12.Text:=( ListView1.Items[I].SubItems[3]);
    SendMailTo.Text:=( ListView1.Items[I].SubItems[4]);


    end;

  inc(I);
 ListView1.Refresh;
 Listview1.items.delete(0);
end;

I've been trying lots of things but nothing seems to work.

I also need it to finish the execution of say the first one and then go into the second one and so on.
I guess i could do that with a boolean expresion.
Most of all i need the loop to work.

Please help

Thanks !!!

0
Comment
Question by:stevencool2000
[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
  • 13
  • 10
23 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 10745673
You should start deleteing from the end.
Or delete always Item[0]
0
 
LVL 17

Expert Comment

by:mokule
ID: 10745684
while  ListView1.Items.Count > 0  do
  begin
   ID.Text:=( ListView1.Items[ 0 ].Caption);
......
0
 
LVL 17

Expert Comment

by:mokule
ID: 10745718
fwhile  ListView1.Items.Count > 0  do
 begin
    ID.Text:=( ListView1.Items[0].Caption);
    Edit9.Text:=( ListView1.Items[0].SubItems[0]);
    Edit10.Text:=( ListView1.Items[0].SubItems[1]);
    Edit11.Text:=( ListView1.Items[0].SubItems[2]);
    Edit12.Text:=( ListView1.Items[0].SubItems[3]);
    SendMailTo.Text:=( ListView1.Items[0].SubItems[4]);
    end;
 ListView1.Refresh;
 Listview1.items.delete(0);
end;

0
Technology Partners: 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!

 

Author Comment

by:stevencool2000
ID: 10745734
The loop is still not right.
It's not moving the item that it has deleted or cleared, it's moving the next one on the row :(

 
0
 

Author Comment

by:stevencool2000
ID: 10745757
The While loops are not working :(
Your code would work fine on a listbox but it's not working for a listview for some reason :(
0
 
LVL 17

Expert Comment

by:mokule
ID: 10745760
Should be in this order

 Listview1.items.delete(0);
 ListView1.Refresh;

What does that mean it's not moving?
0
 
LVL 17

Expert Comment

by:mokule
ID: 10745790
I think it is not necessry

 ListView1.Refresh;

What do You mean not working. I've tested it and it's OK.
0
 

Author Comment

by:stevencool2000
ID: 10745797
Well, say we start with the first line, it gets all the items and puts them in different editboxes.
The problem is that it's not moving the one that it has deleted to the edit boxes, it's showing the next one down :(  Strange!!!
0
 

Author Comment

by:stevencool2000
ID: 10745808
It's actually moving the last in the list and erasing a another one.

For example:

I have :  line 1
             line 2
             line 3

It's deleting line 1 and moving line 3 to the edit boxes.
0
 
LVL 17

Expert Comment

by:mokule
ID: 10745816
Please send Your code once more. It's not possible
0
 
LVL 17

Expert Comment

by:mokule
ID: 10745843
You must refresh Your Form or Edit boxes not ListView
0
 

Author Comment

by:stevencool2000
ID: 10745850
Here it is:

procedure TOBJ_MainForm.Button3Click(Sender: TObject);
var
I: Integer;

Begin

for I:= 0 to ListView1.Items.Count -1  do
begin


    ID.Text:=( ListView1.Items[I].Caption);
    Edit9.Text:=( ListView1.Items[I].SubItems[0]);
    Edit10.Text:=( ListView1.Items[I].SubItems[1]);
    Edit11.Text:=( ListView1.Items[I].SubItems[2]);
    Edit12.Text:=( ListView1.Items[I].SubItems[3]);
    SendMailTo.Text:=( ListView1.Items[I].SubItems[4]);


    end;

  inc(I);
 Listview1.items.delete(0);
 ListView1.Refresh;



end;
0
 
LVL 17

Expert Comment

by:mokule
ID: 10745854
It must work

while  ListView1.Items.Count > 0  do
 begin
    ID.Text:=( ListView1.Items[0].Caption);
    Edit9.Text:=( ListView1.Items[0].SubItems[0]);
    Edit10.Text:=( ListView1.Items[0].SubItems[1]);
    Edit11.Text:=( ListView1.Items[0].SubItems[2]);
    Edit12.Text:=( ListView1.Items[0].SubItems[3]);
    SendMailTo.Text:=( ListView1.Items[0].SubItems[4]);
    end;
 Listview1.items.delete(0);
 Form1.Refresh;     // Refreshes Edit boxes or whatever Your form's name is
end;

0
 

Author Comment

by:stevencool2000
ID: 10745861
Evertime the button is clicked it must transfer the top listview items to the edit boxes and erase itself from the listview...etc...etc...

That's all i need it to do.
0
 
LVL 17

Expert Comment

by:mokule
ID: 10745863
No.
Please note the line

while  ListView1.Items.Count > 0  do


and

 Form1.Refresh;     // Refreshes Edit boxes or whatever Your form's name is

there is no
Inc(I)
there is no I at all.
It'll be good
0
 

Author Comment

by:stevencool2000
ID: 10745880
I've tried what you pasted and nothing is deleted from the listview and the application get's stuck :(

0
 
LVL 17

Expert Comment

by:mokule
ID: 10745892
It is working.
Do You change Form1 to Your Forms name

while  ListView1.Items.Count > 0  do
 begin
    ID.Text:=( ListView1.Items[0].Caption);
    Edit9.Text:=( ListView1.Items[0].SubItems[0]);
    Edit10.Text:=( ListView1.Items[0].SubItems[1]);
    Edit11.Text:=( ListView1.Items[0].SubItems[2]);
    Edit12.Text:=( ListView1.Items[0].SubItems[3]);
    SendMailTo.Text:=( ListView1.Items[0].SubItems[4]);
    end;
 Listview1.items.delete(0);
 OBJ_MainForm.Refresh;     // Refreshes Edit boxes or whatever Your form's name is
end;
0
 
LVL 17

Accepted Solution

by:
mokule earned 125 total points
ID: 10745926
MY FAULT ERROR IN COPY

Do You change Form1 to Your Forms name

while  ListView1.Items.Count > 0  do
 begin
    ID.Text:=( ListView1.Items[0].Caption);
    Edit9.Text:=( ListView1.Items[0].SubItems[0]);
    Edit10.Text:=( ListView1.Items[0].SubItems[1]);
    Edit11.Text:=( ListView1.Items[0].SubItems[2]);
    Edit12.Text:=( ListView1.Items[0].SubItems[3]);
    SendMailTo.Text:=( ListView1.Items[0].SubItems[4]);
///// not here    end;
 Listview1.items.delete(0);
 OBJ_MainForm.Refresh;     // Refreshes Edit boxes or whatever Your form's name is
end;

0
 

Author Comment

by:stevencool2000
ID: 10745935
Sorry, but it doesn't work :(
0
 
LVL 17

Expert Comment

by:mokule
ID: 10745941
Is it OK now after deleting this
fatal end; ?
0
 

Author Comment

by:stevencool2000
ID: 10745944
It now worked but it took all of them in one go...let me try one thing please, 1 minute

0
 

Author Comment

by:stevencool2000
ID: 10745953
Great !!! It now works fine :)

Tanks a lot for you time and help.

Here are your points :)

Thanks again !!!
0
 
LVL 17

Expert Comment

by:mokule
ID: 10745961
Happy to help :)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month11 days, left to enroll

628 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