Export DataGridView to text file with header
<p>I want to export <code>DataGridView</code> to a text file. I write this code. It works fine but I want to write column headers to the textfile too.</p>

<pre><code>SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "Text File|*.txt";
var result = dialog.ShowDialog();
if (result != DialogResult.OK)
    return;
StringBuilder builder = new StringBuilder();
int rowcount = dgvSum.Rows.Count;
int columncount = dgvSum.Columns.Count;

for (int i = 0; i &lt; rowcount - 1; i++)
{
    List&lt;string&gt; cols = new List&lt;string&gt;();
    for (int j = 0; j &lt; columncount - 1; j++)
    {
        cols.Add(dgvSum.Rows[i].Cells[j].Value.ToString());
    }
    builder.AppendLine(string.Join("\t", cols.ToArray()));
}
System.IO.File.WriteAllText(dialog.FileName, builder.ToString());
MessageBox.Show(@"Text file was created.");
</code></pre>