Solved

Listview Loop Problem (Urgent)

Posted on 2004-04-02
23
210 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
  • 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
 

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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now