I have created a WinForms note app using C# and VS2015, in which the user can write notes and save it temporally while the form is opened. But once the user has closed the app and re-opened it, his saved notes will disappear. How can I save the notes for the next open so that he can see, edit and read them again? Here's my code:
private void Form1_Load(object sender, EventArgs e)
{
table = new DataTable();
table.Columns.Add("Title", typeof(string));
table.Columns.Add("Message", typeof(string));
dataGridView1.DataSource = table;
dataGridView1.Columns["Message"].Visible = false;
dataGridView1.Columns["Title"].Width = 140;
}
private void btnNew_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
}
private void btnSave_Click(object sender, EventArgs e)
{
table.Rows.Add(textBox1.Text, textBox2.Text);
textBox1.Clear();
textBox2.Clear();
}
private void btnRead_Click(object sender, EventArgs e)
{
int index = dataGridView1.CurrentCell.RowIndex;
if (index > -1)
{
textBox1.Text = table.Rows[index].ItemArray[0].ToString();
textBox2.Text = table.Rows[index].ItemArray[1].ToString();
}
}
private void btnDelete_Click(object sender, EventArgs e)
{
int index = dataGridView1.CurrentCell.RowIndex;
table.Rows[index].Delete();
}