dualshck012
Active member
I have a databind datagridview with 4 columns, except for the first column which is an added column in the control for a symbol/color row. The first column will be filter flag to indicate an active or inactive users(Doctors). The 2nd column is a databinded column from database which has the value of either 0 or 1 (inactive or active). If the value is 0, the 1st datagridview column will indicate a corresponding inactive image/red color row, else if the value is '1' it will indicate a corresponding active image/green color row. I have a recent C# code here, but it's doing nothing on my control.
My Datagriview load event:
C#:
private void dg_vw_actve_doc_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 1 && !isInit)
{
var valueCell = dg_vw_actve_doc.Rows[e.RowIndex].Cells[e.ColumnIndex];
var imgCell = dg_vw_actve_doc.Rows[e.RowIndex].Cells[e.ColumnIndex + 1]; // Whatever index your colImg is
// char firstCharacterInCell = valueCell.Value.ToString()[1];
//if (firstCharacterInCell == 'A')
if (int.Parse(valueCell.Value.ToString()) == 1)
imgCell.Value = Properties.Resources.active;
else
imgCell.Value = Properties.Resources.inactive;
}
}
My Datagriview load event:
C#:
private void LOAD_ACTIVE_DOCTORS()
{
try
{
mysqlconstring.conn.Open();
string query301 = "SELECT hprovider.chatactv, CONCAT(hpersonal.firstname, ' ', hpersonal.lastname) AS 'Doctors', accno as 'Accreditation' FROM hpersonal INNER JOIN hprovider ON hpersonal.employeeid=hprovider.employeeid WHERE hprovider.licno LIKE 'MD%'";
mysqlconstring.cmd = mysqlconstring.conn.CreateCommand();
mysqlconstring.cmd.CommandType = CommandType.Text;
mysqlconstring.cmd.CommandText = query301;
mysqlconstring.adapt.SelectCommand = mysqlconstring.cmd;
DataSet dtSet = new DataSet();
mysqlconstring.adapt.Fill(dtSet);
dg_vw_actve_doc.DataSource = dtSet.Tables[0].DefaultView;
// to hide unbound column
if (dg_vw_actve_doc.Columns.Count != 0)
{
dg_vw_actve_doc.Columns[1].Visible = true;
}
}
catch (MySqlException err01)
{
MessageBox.Show(err01.ToString(), "Their is an Error in the Database connection. Please contact your SH System Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error);
throw;
}
finally
{
if (mysqlconstring.conn.State == ConnectionState.Open)
{
mysqlconstring.conn.Close();
}
}
}