I have code that allows you to save datagrid information in visual studio into a text file but the datagrid is filled out and it just shows nothing in the text file
Code:
private void button3_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.FileName = "untitled.txt";
sfd.DefaultExt = "txt";
sfd.Filter = "txt files (*.text) |*.txt*";
if (sfd.ShowDialog() == DialogResult.OK)
{
Stream fileStream = sfd.OpenFile();
StreamWriter sw = new StreamWriter(fileStream);
for(int i = 0; i < dataGridView1.Rows.Count - 1; i++) //rows
{
for (int j = 0; j < dataGridView1.Columns.Count; j++) // columns
{
sw.Write("\t", dataGridView1.Rows[i].Cells[j].Value.ToString() + "\t" + "|");
}
sw.WriteLine("");
}
sw.Close();
fileStream.Close();
}
}