[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Problem Saving ListView

Posted on 2007-10-02
17
Medium Priority
?
420 Views
Last Modified: 2010-04-04
I am using ADVListView Component although I think this might be a general problem.

My problem is that I am loading a CSV file into the listview and then sorting the data out.

This is fine, but after that I am inserting a new column and numbering this column which is fine until I save it.

When I save it and open the CSV in Excel, the new column only contains the header but no items.

Anyone have any ideas of why this is happening please?

Thanks

ST3VO
0
Comment
Question by:ST3VO
  • 8
  • 5
  • 3
  • +1
17 Comments
 

Author Comment

by:ST3VO
ID: 19998989
I have noticed something else with the new column on the listview.

Unlike the other columns I cannot select the data fields on the newly create Column.

Could this mean something?

Cheers

ST3VO
0
 

Author Comment

by:ST3VO
ID: 19999083
Can anyone help please? :o(
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 19999341
sorry, I've never used ADVListView
0
Independent Software Vendors: 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!

 
LVL 26

Expert Comment

by:Tomas Helgi Johannsson
ID: 19999426
      Hi!

Post the code where you insert the column.

Regards,
   Tomas Helgi
0
 

Author Comment

by:ST3VO
ID: 19999534
OK...I'm going to try something else that will work.

I've create a column called ID and populated the ListView with it.

The ID Column contains numbers ALL '1's'

What I need to do is replace those numbers from 1 to listview count.

How do I do this please?

Thanks

ST3VO
0
 

Author Comment

by:ST3VO
ID: 19999555
Here is the code:

procedure TForm1.Button12Click(Sender: TObject);
var
      newCol: TListColumn;
      z,j : integer;
      existItem: TListItem;
begin

      j:=0;

        //if ID Column already exists then exit
    //   if ListView1.Columns.Items[j].Caption =('ID') then exit;
         ListView1.Columns.Items[j].Caption :=('ID');
       //add a dummy ID column
    //  newCol := ListView1.Columns.Add;
    // newCol.Index:=0;
    // newCol.Caption := 'ID';

      //Now insert the numbers

      for z := 0 to (ListView1.Items.Count-1) do begin
            //find the current item in the list
            existItem := ListView1.Items[z];
         
            existItem.SubItems.Add( IntToStr(ListView1.Items[z].Index) )

end;
end;

Sorry about all the comments :o)  I've been playing around with it.

Please check my previous post as it might be easier to solve and should work!

Cheers!
0
 
LVL 19

Accepted Solution

by:
MerijnB earned 1050 total points
ID: 19999877
the listview works a little strange regarding columns.
The first column is the .caption property of a TListItem.
The rest of them can be found in SubItems, so the content of column[3] can be found/changed in subitems[2] (note the 3 and 2, not a typo)

so if you insert a column into the listview, you should also insert an entry in the subitems for _every_ item in the listview!

so if you take the code you posted above, and change this line:
            existItem.SubItems.Add( IntToStr(ListView1.Items[z].Index) )

into:

            existItem.SubItems.Insert(0, IntToStr(ListView1.Items[z].Index) )

it should work
0
 
LVL 5

Expert Comment

by:xr1140
ID: 20000194

use SubItems.Add only if the column is added to the listView after you populate the list and SubItems.Insert if you have the column there from the beginning.
0
 

Author Comment

by:ST3VO
ID: 20000272
I still have problems with Saving to CSV. Although the code works, it doesn't save properly which is probably another issue.

That's why I've now added the new column, so it's there.

All I need to do now is replace the subitems of column 0 with number from 1 to listview items count.

xr1140: I've tryed Subitems.insert but I cannot get it to work either. I must be doing something wrong :o/

Can you guys help on replacing the existing subitems please?

0
 
LVL 19

Expert Comment

by:MerijnB
ID: 20001768
what is this CSV thing you are trying to achieve?
0
 

Author Comment

by:ST3VO
ID: 20001856
Hi MerijnB,

Thanks for responding!

I've decided to add the actual column (ID) instead of creating it at runtime because I was having problem when saving it to CSV.

Now it actually saves properly BUT I still have a problem that's driving me crazy :o/

The Existing ID Column contains all 1's as subitems + the Header (ID).

Now, I need to replace all existing subitems of the first Column (With is ID) with numbers from 1 to Listview Items Count.

This is working too BUT instead of replacing the subitems of index 0 it's replacing the subitems of index 1 on the listview.

I just cannot see what I'm doing wrong here :o(

Here is the code:

procedure TForm1.Button12Click(Sender: TObject);
var

      z : integer;
      existItem: TListItem;
begin


      ListView1.Columns.insert(0);


      //Now insert the numbers

      for z := 0 to (ListView1.Items.Count-1) do begin
            //find the current item in the list
            existItem := ListView1.Items[z];
           existItem.SubItems.Insert(0, IntToStr(ListView1.Items[z].Index) );

   end;
end;

Hope you can spot it!

Thanks a million!!!

ST3VO
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 20001892
if it's the very first column you should set ListView1.Items[z].Caption and not one of it's subitems, is that what you mean?
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 20001950
I'm going to bed since it's getting late here :)

If this last comment didn't help, can please explain what you try to do with the CSV data. Because I'm reading a lot on inserting colums, inserting subitems and saving, but I don't know what you want to change on the >CVS data<. Maybe there is an easier way bypassing TListView all together.
0
 

Author Comment

by:ST3VO
ID: 20002029
Nope...Still not working :o/
0
 
LVL 5

Assisted Solution

by:xr1140
xr1140 earned 450 total points
ID: 20002099
there are 2 ways to do this :

1. format you CVS in such way to incorporate the ID as item and the >CVS Data< as subitems:
     - format cvs
     - add to list
     - save list


2. fill the list, add the ID (here several problems can appear depending on how you fill the list)


i'll advice choosing the first option, just let me know so i can help you
0
 

Author Comment

by:ST3VO
ID: 20002180
Thanks again xr1140.

It's been a long day!

I'll catch up tomorrow...Bedtime now!

Talk to you Tomorrow!

ST3VO
0
 
LVL 5

Expert Comment

by:xr1140
ID: 20009756

so ? did you solve the problem ?
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

872 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