I have load my combobox with the image id and image name from the sql database. I want it if we select any image name in the combobox, the image with that image name will be displayed at another cell. Below code is how i load my datagridview combobox column with data from the database.here is the table from the database can anyone help me? here is the columns in the datagridview
`
string constr = @"Data Source=DESKTOP-909N2K6\SQLEXPRESS;Initial Catalog=project1;Integrated Security=True";
using (SqlConnection conn = new SqlConnection(constr))
{
using (SqlDataAdapter sda = new SqlDataAdapter("SELECT shapeID, shapeCode FROM shapeTable order by shapeCode asc ", conn))
{
//Fill the DataTable with records from Table.
DataTable dt = new DataTable();
sda.Fill(dt);
//Insert the Default Item to DataTable.
DataRow row = dt.NewRow();
dt.Rows.InsertAt(row, 0);
//Assign DataTable as DataSource, Shape is the comboboxcolumn name that i have add in the datagridview column.
this.Shape.DisplayMember = "shapeCode";
this.Shape.ValueMember = "shapeID";
this.Shape.DataSource = dt;
}
}
`
i already tried using this code, but i have problem with requiring the comboboxcolumn selected value and the code does not work.
Edited : i have required the way to retrieve the combobox column value, now i dont know the right way to display the image column with the image that belong to the combobox column value.
void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
if (dataGridView1.IsCurrentCellDirty)
{
// This fires the cell value changed handler below
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
}
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
DataGridViewComboBoxCell Shape = (DataGridViewComboBoxCell)dataGridView1.Rows[e.RowIndex].Cells[10];
if (Shape.Value != null)
{
// the code to display image based on the value retrieve from the combobox column
dataGridView1.Invalidate();
}
}
okay I've already got the answer. here are the example of ui