views:

6

answers:

0

I have this in my code to retreive the ListView contents and save to a file. But the alignment is wrong. How do I set it to be right?

// save to textfile StreamWriter sw = new StreamWriter(@"D:\test.txt", false); // false=not append sw.WriteLine("Items Unit Price Quantity Total Price"); sw.WriteLine("----- ---------- -------- -----------"); string st1; for (int row = 0; row < listView1.Items.Count; row++) { st1 = "\n"; for (int col = 0; col < listView1.Columns.Count; col++) { st1 += listView1.Items[row].SubItems[col].Text.ToString(); } sw.WriteLine(st1); }

The wrong output is as below: Items Unit Price Quantity Total Price ----- ---------- -------- -----------

Strawberries0.0510.05

Bananas0.1020.20

Oranges0.2030.60

Apples0.2541.00

Pears0.3051.50

California Raisin Bread0.3562.10

Fruit and Nut Bread0.4072.80

Corn Bread0.4583.60

Banana Walnut Bread0.5094.50

Low GI Nutri Multi-Grain Bread0.55105.50

Focaccia Bread0.6095.40

Wholemeal Bread0.6585.20

Sweetcorn Bun0.7074.90

Vanilla Bun0.7564.50

PediaSure0.8054.00

Isomil 2 Advance0.8543.40

Grow School0.9032.70

Similac0.9521.90

Grow1.0011.00

GainIQ Kid1.0522.10

Coca-Cola1.1033.30

Coca-Cola C21.1544.60

Coca-Cola Light1.2056.00

Coca-Cola Zero1.2567.50

Diet Coke1.3079.10

Diet Coke with Lemon1.35810.80

The output which I want is as below: Items Unit Price Quantity Total Price ----- ---------- -------- -----------

Strawberries 0.05 1 0.05

Bananas 0.10 2 0.20

Oranges 0.20 3 0.60

Apples 0.25 4 1.00

Pears 0.30 5 1.50

California Raisin Bread 0.35 6 2.10

Fruit and Nut Bread 0.40 7 2.80

Corn Bread 0.45 8 3.60

Banana Walnut Bread 0.50 9 4.50

Low GI Nutri Multi-Grain Bread 0.55 10 5.50

Focaccia Bread 0.60 9 5.40

Wholemeal Bread 0.65 8 5.20

Sweetcorn Bun 0.70 7 4.90

Vanilla Bun 0.75 6 4.50

PediaSure 0.80 5 4.00

Isomil 2 Advance 0.85 4 3.40

Grow School 0.90 3 2.70

Similac 0.95 2 1.90

Grow 1.00 1 1.00

GainIQ Kid 1.05 2 2.10

Coca-Cola 1.10 3 3.30

Coca-Cola C2 1.15 4 4.60

Coca-Cola Light 1.20 5 6.00

Coca-Cola Zero 1.25 6 7.50

Diet Coke 1.30 7 9.10

Diet Coke with Lemon 1.35 8 10.80

related questions