I have a datagridview in windows control form where I insert a checkbox column beside a data table queried from MYSQL database
private void ControlForm_Load(object sender, EventArgs e)
{
DataGridViewCheckBoxColumn ChkboxCol = new DataGridViewCheckBoxColumn();
ChkboxCol.HeaderText = "Checkbox";
ChkboxCol.Width = 50;
ChkboxCol.Name = "Checkbox";
ChkboxCol.TrueValue = true;
ChkboxCol.FalseValue = false;
dataGridView1.Columns.Insert(0, ChkboxCol);
int ColCount = dataGridView1.ColumnCount;
dataGridView1.DataSource = tablequery();
}
public DataTable tablequery()
{
MY_DB DB = new MY_DB();
string query = "SELECT * FROM sometable";
MySqlCommand cmd = new MySqlCommand(query, DB.GetConnection);
MySqlDataAdapter adapter = new MySqlDataAdapter();
DataTable table = new DataTable();
adapter.SelectCommand = cmd;
adapter.Fill(table);
return table;
}
In the "sometable" table in MySQL, I have set the data type to be TINYINT (which arise after I select Boolean) in the "Checkbox_Value" column and I have set the number to be 0 or 1. I would want my results on the checkbox column of my datagrid to reflect as checked if the "Check_Value" of a particular entry to be 1 or unchecked if the "Check_value" of another particular entry is 0. The number of entries in the "sometable" and the value of the "Check_Value" would change and I wish this checkbox could reflect the checked status dynamically.
Thank you very much for any suggestion or advice.
I have included the table of my DB
where the column "XXXX" is the set_active column