I have a SQL Database that contains a bit column and whenever a checkbox is clicked I want to update the bit column field with the current value.
All works great except the DataGridView doesn't update and I have to reload it to see the changes (checked/unchecked). I tried with Refresh() and RefreshEdit() but it doesn't work.
private void dgv_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
SqlConnection db = new SqlConnection(Properties.Settings.Default.BikesConn);
if (e.ColumnIndex == 1)
{
if (dgv.Rows[e.RowIndex].Cells["Selected"].Value.ToString() == "True")
{
SqlCommand cmd = new SqlCommand(string.Format("UPDATE {0} SET Selected='0' WHERE ID={1}", Properties.Settings.Default.Profile, dgv.SelectedRows[0].Cells[0].Value.ToString()), db);
db.Open();
cmd.ExecuteNonQuery();
db.Close();
//loadGridViewer(Properties.Settings.Default.Profile);
}
if (dgv.Rows[e.RowIndex].Cells["Selected"].Value.ToString() == "False")
{
SqlCommand cmd = new SqlCommand(string.Format("UPDATE {0} SET Selected='1' WHERE ID={1}", Properties.Settings.Default.Profile, dgv.SelectedRows[0].Cells[0].Value.ToString()), db);
db.Open();
cmd.ExecuteNonQuery();
db.Close();
//loadGridViewer(Properties.Settings.Default.Profile);
}