I have a winform program written in C# using VS 2010.
I edit the rows from the data grid view by clicking one, take that data from the row and populate textboxes with it, edit as needed the send back to my data grid.
What I want to is have an image related to each row in my data grid view (e.g. a picture of an employee) that would appear in a picture box when that particular row is selected.
In short, if I click employee Andrew, Andrew's picture appears, if I click Rasheed, Rasheeds picture appears and so on.
The picture box is outside of the data grid view, so is not in another column. It is just stand alone.
Could anyone give me some help on this?
Code for selecting row and sending to textboxes:
// Displays Customer infomation in Update Area
if (e.RowIndex < 0 || e.ColumnIndex < 0)
{
}
else
{
if (customersDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
{
textBox_customerID.Text = "" + customersDataGridView.Rows[e.RowIndex].Cells["Customer_ID"].Value.ToString();
textBox_forename.Text = customersDataGridView.Rows[e.RowIndex].Cells["Forename"].Value.ToString();
textBox_surname.Text = customersDataGridView.Rows[e.RowIndex].Cells["Surname"].Value.ToString();
textBox_address.Text = customersDataGridView.Rows[e.RowIndex].Cells["Address"].Value.ToString();
textBox_town.Text = customersDataGridView.Rows[e.RowIndex].Cells["Town"].Value.ToString();
textBox_postcode.Text = customersDataGridView.Rows[e.RowIndex].Cells["Postcode"].Value.ToString();
textBox_dateofbirth.Text = customersDataGridView.Rows[e.RowIndex].Cells["Date_Of_Birth"].Value.ToString();
textBox_phonenum.Text = customersDataGridView.Rows[e.RowIndex].Cells["Phone_Number"].Value.ToString();
textBox_email.Text = customersDataGridView.Rows[e.RowIndex].Cells["Email"].Value.ToString();
textBox_current_rental.Text = customersDataGridView.Rows[e.RowIndex].Cells["Current_Rental"].Value.ToString();
}
Code for updating rows and sending back to data grid:
DialogResult dialogResult = MessageBox.Show("Are you sure you want to update this customer? ", "Update - " + textBox_forename.Text + textBox_surname.Text, MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{// Updates Product Info
if (textBox_customerID.Text == "" || textBox_forename.Text == "" || textBox_surname.Text == "" || textBox_address.Text == "" || textBox_town.Text == "" || textBox_postcode.Text == "" || textBox_dateofbirth.Text == "" || textBox_phonenum.Text == "" || textBox_email.Text == "" || textBox_current_rental.Text == "")
{
MessageBox.Show("Please leave no boxes blank");
}
else
{
string custData = textBox_customerID.Text;
command.CommandText = "UPDATE customers SET Customer_ID = '" + textBox_customerID.Text + "', Forename = '" + textBox_forename.Text + "', Surname = '" + textBox_surname.Text + "', Address = '"
+ textBox_address.Text + "', Town = '" + textBox_town.Text + "', Postcode = '" + textBox_postcode.Text + "', Date_Of_Birth = '" + textBox_dateofbirth.Text + "', Phone_Number = '" + textBox_phonenum.Text + "', Email = '" + textBox_email.Text + "', Current_Rental = '" + textBox_current_rental.Text + "' WHERE Customer_ID = '" + custData + "'";
connect.Open();
command.Connection = connect;
command.ExecuteNonQuery();
connect.Close();
customersDataGridView.Rows.Clear();
refreshCustomers();
MessageBox.Show("Customer Updated");