Bonjour,
J'essaie de manipuler les fonctions ci-dessous sur mon datagridview mais rien ne se passe.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 //Adding a New Record here private void dataGridView1_RowLeave(object sender, DataGridViewCellEventArgs e) { string studentId = dataGridView1.CurrentRow.Cells["StudentId"].Value.ToString(); if (studentId.Equals(string.Empty)) { StudentBO objStudentBO = new StudentBO(); try { objStudentBO.RollNumber = dataGridView1.CurrentRow.Cells["RollNumber"].Value.ToString(); objStudentBO.FirstName = dataGridView1.CurrentRow.Cells["FirstName"].Value.ToString(); objStudentBO.LastName = dataGridView1.CurrentRow.Cells["LastName"].Value.ToString(); objStudentBO.Gender = dataGridView1.CurrentRow.Cells["Gender"].Value.ToString(); objStudentBO.Stream = dataGridView1.CurrentRow.Cells["Stream"].Value.ToString(); StudentBL.AddNewStudentDetails(objStudentBO); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 //Deleting a Record private void dataGridView1_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) { try { Int32 iStudentId = Convert.ToInt32(dataGridView1.CurrentRow.Cells["StudentId"].Value); DialogResult result1 = MessageBox.Show("Are you sure you want to delete this Student Record?", "Delete the Record", MessageBoxButtons.YesNo); if (result1 == DialogResult.Yes) { int result = StudentBL.RemoveStudent(iStudentId); if (result > 0) { //Record deleted successfully //showing the new refreshed data showData(); } } }//try catch (Exception ex) { //MessageBox.Show(ex.Message); MessageBox.Show("Cannot Delete Record"); } }?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 //Updating a Record here private void dataGridView1_CellLeave(object sender, DataGridViewCellEventArgs e) { string studentId = dataGridView1.CurrentRow.Cells["StudentId"].Value.ToString(); if (!studentId.Equals(string.Empty)) { StudentBO objStudentBO = new StudentBO(); objStudentBO.StudentId = Convert.ToInt32(dataGridView1.CurrentRow.Cells["StudentId"].Value); objStudentBO.RollNumber = dataGridView1.CurrentRow.Cells["RollNumber"].Value.ToString(); objStudentBO.FirstName = dataGridView1.CurrentRow.Cells["FirstName"].Value.ToString(); objStudentBO.LastName = dataGridView1.CurrentRow.Cells["LastName"].Value.ToString(); objStudentBO.Gender = dataGridView1.CurrentRow.Cells["Gender"].Value.ToString(); objStudentBO.Stream = dataGridView1.CurrentRow.Cells["Stream"].Value.ToString(); StudentBL.UpdateStudentDetails(objStudentBO); } }
Merci,
Partager