?
Solved

C# -- Checkbox STATE -- still fails ?

Posted on 2009-12-23
5
Medium Priority
?
280 Views
Last Modified: 2013-12-17
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");
                }
            }
        }
0
Comment
Question by:finance_teacher
  • 3
5 Comments
 
LVL 3

Accepted Solution

by:
KinjalKumar Patel earned 1000 total points
ID: 26116380
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
 
LVL 15

Assisted Solution

by:rajeeshmca
rajeeshmca earned 1000 total points
ID: 26117511
Hi finance_teacher,


either frame it as

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

or

if (designerMaintenanceDataGridView["IsDesigner", i].Value == true)
{
}
0
 

Author Comment

by:finance_teacher
ID: 26119000
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
 

Author Comment

by:finance_teacher
ID: 26119228
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
 

Author Comment

by:finance_teacher
ID: 26119523
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

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question