Hi,
Thanks to help in this forum, I got the CheckBox working visually. How do I check what the state of the CheckBox is? It seems to behave very strangely. I had looked at several values including "Value" and "EditedFormattedValue" and non appears to work correctly. "EditedFormattedValue" seems to work opposite and "Value" never changes from "false" no matter the physical state of the CheckBox. Below is the DataGridViewCheckBoxCell definition and the second section is the DataGridView_CellMouseClick routine.
Thanks to help in this forum, I got the CheckBox working visually. How do I check what the state of the CheckBox is? It seems to behave very strangely. I had looked at several values including "Value" and "EditedFormattedValue" and non appears to work correctly. "EditedFormattedValue" seems to work opposite and "Value" never changes from "false" no matter the physical state of the CheckBox. Below is the DataGridViewCheckBoxCell definition and the second section is the DataGridView_CellMouseClick routine.
C#:
dgvQuery.Columns.Add("Column" + e.Index, clbFPYFields.SelectedItem.ToString());
if (dgvQuery.Columns.Count == 1)
{
dgvQuery.Rows.Add();
DataGridViewComboBoxCell cbCell = new DataGridViewComboBoxCell();
cbCell.Items.Add("Ascending");
cbCell.Items.Add("Descending");
cbCell.Items.Add("[not sorted]");
dgvQuery[0, 0] = cbCell;
dgvQuery[0, 0].Value = "[not sorted]";
dgvQuery.Rows[0].HeaderCell.Value = "Sort";
dgvQuery.Rows.Add();
DataGridViewCheckBoxCell chkCell = new DataGridViewCheckBoxCell();
chkCell.TrueValue = true;
chkCell.FalseValue = false;
dgvQuery[0, 1] = chkCell;
dgvQuery[0, 1].Value = false;
dgvQuery.Rows[1].HeaderCell.Value = "Show";
dgvQuery.Rows.Add();
DataGridViewButtonCell btnCell = new DataGridViewButtonCell();
btnCell.Value = "Edit";
dgvQuery[0, 2] = btnCell;
dgvQuery.CellMouseClick += new DataGridViewCellMouseEventHandler(dgvQuery_CellMouseClick);
dgvQuery.Rows[2].HeaderCell.Value = "Criteria";
dgvQuery.Rows.Add();
dgvQuery.Rows[3].HeaderCell.Value = "Query";
dgvQuery.Rows[3].ReadOnly = true;
}
C#:
private void dgvQuery_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
switch (e.RowIndex)
{
case 1: // Show CheckBox
DataGridView myView = (DataGridView)sender;
DataGridViewCheckBoxCell myCell = (DataGridViewCheckBoxCell)myView[e.ColumnIndex, e.RowIndex];
if (Convert.ToBoolean(myCell.Value) == true)
{
}
else
{
}
break;
case 2: // Edit Button
frmCriteria frmShowCriteria = new frmCriteria();
DialogResult drButton;
sQueryField = dgvQuery.Columns[e.ColumnIndex].HeaderCell.Value.ToString();
if (dgvQuery[e.ColumnIndex, 3].Value != null)
sSQLQuery = dgvQuery[e.ColumnIndex, 3].Value.ToString();
else
sSQLQuery = "";
drButton = frmShowCriteria.ShowDialog();
if (drButton == System.Windows.Forms.DialogResult.OK)
{
dgvQuery[e.ColumnIndex, 3].Value = sSQLQuery;
}
break;
}
}