private void ButtonEditUser_Click(object sender, EventArgs e) { User objt = new User { ID = int.Parse(dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[0].Value.ToString()), Name = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[1].Value.ToString(), Surname = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[2].Value.ToString(), Address = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[3].Value.ToString(), Function = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[4].Value.ToString(), Login = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[5].Value.ToString(), Password = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[6].Value.ToString() }; if (objt != null) { using (EditAddUserPanel frm = new EditAddUserPanel() { UserInfo = objt }) { if (frm.ShowDialog() == DialogResult.OK) { int userId = int.Parse(dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[0].Value.ToString()); var user = listOfUser.FirstOrDefault(u => u.ID == userId); listOfUser.Remove(user); listOfUser.Add(frm.UserInfo); SortListOfUser(); RefreshDataGridView(); } } } }
private void ButtonAddUser_Click(object sender, EventArgs e) { using (EditAddUserPanel frm = new EditAddUserPanel() { UserInfo = new User() }) { if (frm.ShowDialog() == DialogResult.OK) { listOfUser.Add(frm.UserInfo); } } SortListOfUser(); RefreshDataGridView(); }