Reputation: 15
Im trying to get values clicking on datagrid...I got the values from textobox and combobox...but when Im trying to get a value from a boolean the form doesnt work...
private void dtg_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (dtg.CurrentRow != null)
{
txtId.Text = dtg.CurrentRow.Cells["ID"].Value.ToString();
txtCode.Text = dtg.CurrentRow.Cells["CODE"].Value.ToString();
//BOOLEAN
ckbActive.Checked = Convert.ToBoolean(dtg.CurrentRow.Cells["ACTIVE"].ToString());
What I need is get the value on "ACTIVE" column in ckbActive form Control...
Upvotes: 1
Views: 5559
Reputation: 66449
Calling ToString()
directly on the cell gets you the name of the type of column (i.e. "DataGridViewTextBoxCell" or similar), which can't be converted to a valid boolean:
ckbActive.Checked = Convert.ToBoolean(dtg.CurrentRow.Cells["ACTIVE"].ToString());
The actual value of the cell is accessible through the Value
property, so use this instead:
ckbActive.Checked = Convert.ToBoolean(dtg.CurrentRow.Cells["ACTIVE"].Value);
Upvotes: 1