Vuk Stanojevic

Vuk Stanojevic

  • 1.5k
  • 140
  • 42k

C# export datagridview to TXT

Oct 30 2020 1:09 PM
Hi everyone,
i have datagridview which i need to export to txt file.
This datagridview have 13 columns(fixed) and number of rows is unlimited.
Now i need to export all this data to TXT file.
Each line of this txt file should be like column[0]+column[1]+column[3]+column[4]+column[5]+column[6]+column[7]+column[8]+column[9]+column[10]+column[11]+column[12].
Since that in txt column[0]+column[1] max lenght is 54 and if lenght is less then 54 other free spaces must be empty string, then column[3] starting position is 54 and lenght is  10, column[4] starting position is 64 and lenght is 3....
and like this i have to do with all 13 columns.
In datagrid columnes i alrady did PadRight and PadLeft in order to fill spaces if lenght is less then requested.
Now when i export it i doesn't get what i want, i get more spaces between columns values.
Can you help?
Thank you. 

Answers (2)