I am novice coder in C# and I am currently working with a report generator. I am reading data from a text file and displaying the results in multi-line textbox. I am currently having issues with formatting the data so it will look neat and professional. I am adding string with spaces for separation but its making the data look uneven.
Is there away to display the data in the multi-line textbox just as the picture below shows? Also, is there away to populate the multi-line textbox with titles when the form is started?

Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private static string newLine = Environment.NewLine;
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
{
double grandtotal = 0.0;
int totalcount = 0;
string space2 = " ";
string space3 = " ";
for( int i = 0; i < 100; i++ ) {
grandtotal += totalSales[i];
totalcount += count[i];
}
StringBuilder sb = new StringBuilder();
textBox1.AppendText( "Product Name" + space2 + "Total Sales" + space3 + "Average" + newLine );
for( int i = 0; i < 100; i++ ) {
if( productName[i] != null ) {
if( totalSales[i] != 0 ) {
textBox1.AppendText( productName[i] + space3
+ totalSales[i] + space3
+ ( totalSales[i] / count[i] ).ToString( "#.##" ) + newLine );
}
}
}
textBox1.AppendText( "Grand Total" + space3 + grandtotal
+ space3 + ( grandtotal / totalcount ).ToString( "#.##" ) + newLine );
}
}
}
}
You can use String.Format method.
Here is link that can guide you http://www.dotnetperls.com/string-format.