rowlandsfc
Active member
i have a datagaridview that on form load loads details from a database into it, what id like to do if possible is add a combo box to one of the columns(status) andbe able to change this from either closed or open.
filling datagridview:
private void showProducts()
{
try
{
conn = new SQLiteConnection(dbConnection.source);
string sqlcommand = @"SELECT * FROM product";
da_Products = new SQLiteDataAdapter(sqlcommand, conn);
dt_Products = new DataTable();
da_Products.Fill(dt_Products);
dgv_Products.DataSource = dt_Products;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
got it working with this code:
private void dgv_Products_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex > -1)
{
// Bind grid cell with combobox and than bind combobox with datasource.
DataGridViewComboBoxCell status = new DataGridViewComboBoxCell();
// Check the column cell, in which it click.
if (dgv_Products.Columns[e.ColumnIndex].Name.Contains("status"))
{
// On click of datagridview cell, attched combobox with this click cell of datagridview
dgv_Products[e.ColumnIndex, e.RowIndex] = status;
string[] state = new string[] { "open", "closed" };
status.Items.AddRange(state);
}
}
}
Last edited: