I am new to C# and I have the following question/s:
DBOps.cs:
class DBOps()
{
internal static void Update(DataGridView dataGridView1)
{
if (dataGridView1.SelectedRows.Count != 0)
{
var user = new User();
user.Id = (int) dataGridView1.SelectedRows[0].Cells[0].Value;
user.Username = (string) dataGridView1.SelectedRows[0].Cells[1].Value;
user.FirstName = (string) dataGridView1.SelectedRows[0].Cells[2].Value;
user.LastName = (string) dataGridView1.SelectedRows[0].Cells[3].Value;
user.Email = (string) dataGridView1.SelectedRows[0].Cells[4].Value;
user.Password = (string) dataGridView1.SelectedRows[0].Cells[5].Value;
var updateForm = new UpdateForm(user);
var result = updateForm.ShowDialog();
if (result == DialogResult.OK)
{
}
else if (result == DialogResult.Cancel)
{
}
}
}
}
User.cs:
class User
{
public int Id { get; set; }
public string Username { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Password { get; set; }
}
UpdateForm.cs:
public partial class UpdateForm : Form
{
public UpdateForm(User user)
{
InitializeComponent();
txtId.Text = user.Id.ToString();
txtUser.Text = user.Username;
txtFName.Text = user.FirstName;
txtLName.Text = user.LastName;
txtEmail.Text = user.Email;
txtPass.Text = user.Password;
}
//code
}
The values in DBOps class are stored correctly, I've checked that. Now I want to set the TextBoxes in UpdateForm with the values from User.cs.