Question : 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");
                }
            }
        }

Answer : C# -- Checkbox STATE -- still fails ?

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.
Random Solutions  
 
programming4us programming4us