C# -- Checkbox STATE -- still fails ?

Changing below
  ["IsDesigner"] != null
        to
  ["IsDesigner"].State == unchecked
causes Syntax error, '(' expected

How can I fix ?
-------------------------------------------
        private void designerMaintenanceBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < designerMaintenanceDataGridView.Rows.Count; i++)
            {
                // if ID null & designer checked
                if (designerMaintenanceDataGridView.Rows[i].Cells["ID1"].Value.Equals(System.DBNull.Value)
                    && designerMaintenanceDataGridView.Rows[i].Cells["IsDesigner"].State == unchecked)
                {
                    MessageBox.Show("will be Added");
                    //gmL_ROITEMTableAdapter.AddRomID(iGML_ROMSTR_ID, RoID);
                }

                // if ID NOT null & designer unchecked
                else if (designerMaintenanceDataGridView.Rows[i].Cells["ID1"].Value.ToString().Length > 0
                         && designerMaintenanceDataGridView.Rows[i].Cells["IsDesigner"] == null)
                {
                    MessageBox.Show("will be Deleted");
                    //gmL_ROITEMTableAdapter.DeleteRomID(iGML_ROMSTR_ID, RoID);
                }
                else
                {
                    MessageBox.Show("No Add or Delete Happens");
                }
            }
        }
finance_teacherAsked:
Who is Participating?
 
KinjalKumar PatelConnect With a Mentor Senior Software EngineerCommented:
The problem over here seems to be that the State Property of CheckBoxColumn is of type DataGridViewElementStates and that too is of enumerable type. So when you are specifying it as null there was no problem as it was an object. But when you specify unchecked it was a syntatical error as the value should be one of the value from the enum.

if (designerMaintenanceDataGridView.Rows[i].Cells["ID1"].Value.Equals(System.DBNull.Value)
                    && designerMaintenanceDataGridView.Rows[i].Cells["IsDesigner"].State != DataGridViewElementStates.Selected) may solve your problem.

As you are trying to check for unchecked what i had done is that not equal to selected that is equivalent to not selected.

Let me know if it doesn't works for you than.
0
 
rajeeshmcaConnect With a Mentor Commented:
Hi finance_teacher,


either frame it as

if (designerMaintenanceDataGridView["IsDesigner", i].State == DataGridViewElementStates.Selected)
{
}

or

if (designerMaintenanceDataGridView["IsDesigner", i].Value == true)
{
}
0
 
finance_teacherAuthor Commented:
I tried everything, including the below, and it still fails.
I will do some more research.
---------------------------------------------------------------------
        private void designerMaintenanceBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < designerMaintenanceDataGridView.Rows.Count; i++)
            {
                // if ID null & designer checked
                if (designerMaintenanceDataGridView["IsDesigner",i].State == DataGridViewElementStates.Selected)
                {
                    MessageBox.Show("will be Added");
                    //gmL_ROITEMTableAdapter.AddRomID(iGML_ROMSTR_ID, RoID);
                }

                // if ID NOT null & designer unchecked
                else if (designerMaintenanceDataGridView["IsDesigner", i].State != DataGridViewElementStates.Selected)
                {
                    MessageBox.Show("will be Deleted");
                    //gmL_ROITEMTableAdapter.DeleteRomID(iGML_ROMSTR_ID, RoID);
                }
                else
                {
                    MessageBox.Show("No Add or Delete Happens");
                }
            }
        }
0
 
finance_teacherAuthor Commented:
The below code works half way.
How can I get step #6 and #9 working ?

Steps
 1. run APP
 2. click "Save"
 3. correct "MessageBoxes" display
 4. check everything
 5. click "Save" again
 6. correct "MessageBoxes" display,
    except for the last item,
    since it is still active
 7. uncheck everything
 8. click "Save" again
 9. correct "MessageBoxes" display,
    except for the last item,
    since it is still active
------------------------------------------------------------------------------------------------------------------------------------------------------
        private void designerMaintenanceBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < designerMaintenanceDataGridView.Rows.Count; i++)
            {
                //// if ID null & designer checked              
                if (Convert.ToBoolean(designerMaintenanceDataGridView.Rows[i].Cells["IsDesigner"].Value) == false)
                {
                        MessageBox.Show("Unchecked");
                }
                //// if ID NOT null & designer unchecked
                else if (Convert.ToBoolean(designerMaintenanceDataGridView.Rows[i].Cells["IsDesigner"].Value) == true)
                    {
                        MessageBox.Show("Checked");
                    }
            }
        }
0
 
finance_teacherAuthor Commented:
Below works
-----------------------
        private void designerMaintenanceBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.vNAMEToolStripTextBox.Focus();
            for (int i = 0; i < designerMaintenanceDataGridView.Rows.Count; i++)
            {
                decimal vAD_ID = 0;
                Decimal.TryParse(designerMaintenanceDataGridView.Rows[i].Cells["AD_ID"].Value.ToString(), out vAD_ID);
                // if ID null & designer checked              
                if (designerMaintenanceDataGridView.Rows[i].Cells["AD_ID"].Value.Equals(System.DBNull.Value)
                    && (Convert.ToBoolean(designerMaintenanceDataGridView.Rows[i].Cells["IsDesigner"].Value) == true))
                {
                    MessageBox.Show("Insert Record");
                }

                // if ID NOT null & designer unchecked
                else if (designerMaintenanceDataGridView.Rows[i].Cells["AD_ID"].Value.ToString().Length > 0
                    && (Convert.ToBoolean(designerMaintenanceDataGridView.Rows[i].Cells["IsDesigner"].Value) == false))
                {
                    this.designerMaintenanceTableAdapter.Delete_AD_Record(vAD_ID);
                }
            }
            this.designerMaintenanceTableAdapter.Fill(this.dataSet1.DesignerMaintenance, vNAMEToolStripTextBox.Text);
        }
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.