We help IT Professionals succeed at work.

Problem Saving ListView

ST3VO
ST3VO asked
on
438 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
Comment
Watch Question

Author

Commented:
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

Author

Commented:
Can anyone help please? :o(
MerijnBSr. Software Engineer
CERTIFIED EXPERT

Commented:
sorry, I've never used ADVListView
Tomas Helgi JohannssonDatabase Administrator / Software Engineer
CERTIFIED EXPERT

Commented:
      Hi!

Post the code where you insert the column.

Regards,
   Tomas Helgi

Author

Commented:
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

Author

Commented:
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!
Sr. Software Engineer
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Commented:

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.

Author

Commented:
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?

MerijnBSr. Software Engineer
CERTIFIED EXPERT

Commented:
what is this CSV thing you are trying to achieve?

Author

Commented:
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
MerijnBSr. Software Engineer
CERTIFIED EXPERT

Commented:
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?
MerijnBSr. Software Engineer
CERTIFIED EXPERT

Commented:
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.

Author

Commented:
Nope...Still not working :o/
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks again xr1140.

It's been a long day!

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

Talk to you Tomorrow!

ST3VO

Commented:

so ? did you solve the problem ?

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.