Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
please tell how i could customize the alignment in a text file.i am writing the value of a DataGridview to a text file using file.append method in a table format

What I have tried:

i tried to solve it by finding the length of the string and removing the extra characters to make it aligned
private void Write_InvoiceDetails()
{
p1: if (dgvStock[1, indexing].Value.ToString().Length < 12)
{
dgvStock[1, indexing].Value = dgvStock[1, indexing].Value.ToString() + ".";
goto p1;
}
if (dgvStock[1, indexing].Value.ToString().Length > 12)
dgvStock[1, indexing].Value = dgvStock[1, indexing].Value.ToString().Remove(12);

File.AppendAllText("InvoiceMaster.txt", Environment.NewLine + " " + dgvStock[1, indexing].Value.ToString() + " " +
string.Format(dgvStock[7, indexing].Value.ToString()) + " " + " " + dgvStock[6, indexing].Value.ToString() + " " +
dgvStock[8, indexing].Value.ToString() + " " + dgvStock["discount", indexing].Value.ToString() + " ");

}
Posted
Comments
Richard MacCutchan 14-Oct-16 3:24am    
what are you trying to align it to? You would generally not need to care about this inside the file but only when displaying or printing. You should also get rid of that goto statement, and use a proper loop instead.
Member 12792950 14-Oct-16 4:59am    
i am printing from a text file .so i need to align the datas in a tabular format.how could i?
Karthik_Mahalingam 18-Oct-16 5:25am    
Always use  Reply  button, to post Comments/query to the user, so that the user gets notified and responds to your text.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900