-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotepadApp.cs
More file actions
83 lines (71 loc) · 2.85 KB
/
NotepadApp.cs
File metadata and controls
83 lines (71 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Notepad_2._0
{
public partial class NotepadApp : Form
{
DataTable notes = new DataTable(); // This will act as a backend for the datagridview
bool editing = false; // This will be using to keep in check if the notes are being edited or not
public NotepadApp()
{
InitializeComponent();
}
private void NotepadApp_Load(object sender, EventArgs e)
{
notes.Columns.Add("Title"); // entry for the DataTable
notes.Columns.Add("Note"); // entry for the DataTable
SavedData_Gridview.DataSource = notes; // This will set the DataSource (Gridview) equals to the DataTable
}
private void Save_button_Click(object sender, EventArgs e)
{
if(editing)
{
notes.Rows[SavedData_Gridview.CurrentCell.RowIndex]["Title"] = Title_Textbox.Text;
notes.Rows[SavedData_Gridview.CurrentCell.RowIndex]["Title"] = Note_Textbox.Text;
}
else
{
notes.Rows.Add(Title_Textbox.Text, Note_Textbox.Text);
}
Title_Textbox.Text = "";
Note_Textbox.Text = "";
editing = false;
}
private void Load_button_Click(object sender, EventArgs e)
{
Title_Textbox.Text = notes.Rows[SavedData_Gridview.CurrentCell.RowIndex].ItemArray[0].ToString(); //
Note_Textbox.Text = notes.Rows[SavedData_Gridview.CurrentCell.RowIndex].ItemArray[1].ToString();
editing = true;
}
private void Newnote_button_Click(object sender, EventArgs e)
{
Title_Textbox.Text = "";
Note_Textbox.Text = "";
}
private void Delete_button_Click(object sender, EventArgs e)
{
try
{
notes.Rows[SavedData_Gridview.CurrentCell.RowIndex].Delete(); // This makes sure that the user has selected an index on the DatagridView and deletes it
}
catch (Exception ex) { Console.WriteLine("Not a valid note"); } // show a message in case the user tries to delete an invalid row or column
}
private void SavedData_Gridview_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
Title_Textbox.Text = notes.Rows[SavedData_Gridview.CurrentCell.RowIndex].ItemArray[0].ToString(); //
Note_Textbox.Text = notes.Rows[SavedData_Gridview.CurrentCell.RowIndex].ItemArray[1].ToString();
editing = true;
}
private void exitapp_img_Click(object sender, EventArgs e)
{
this.Dispose();
}
}
}