Click here to Skip to main content
15,902,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I wrote a code that contains Group Box with some checkboxes assigned with some colors, and Data Grid View Table(that contains some data table).

The output i must generate is, whenever i click on a any one of check box in group box, that check box's respective back color should be displayed on the Data Grid View Table.

But, When i wrote this code, i got the following error:

pointing "e.Value.ToString == "Inactive" & this.activeCustomersCheckBox.Checked

"Operator "==" cannot be applied to operands of type 'method group' and 'string'.

please, help me with this error. Awaiting for your reply.


Here is the code which i've written

C#
public class Form
{

    private void Form_Load(System.Object sender, System.EventArgs e)
    {
        // Load data into the 'AjaxDataSet.Customer' DataTable.
        this.CustomerTableAdapter.Fill(this.AjaxDataSet.Customer);

        // Set customerDataGridView column names to the column names
        //   in the data source. (Ajax database Customer table's column names)
        // This will enable us to refer to customerDataGridView columns
        //   by name in this form's customerDataGridView_CellFormatting method.
        int i;
        for (i = 0; i <= this.customerDataGridView.Columns.Count - 1; i++) {
            this.customerDataGridView.Columns[i].Name = this.customerDataGridView.Columns[i].DataPropertyName;
        }

        // Don't allow new records to be added.
        this.customerDataGridView.AllowUserToAddRows = false;

    }

    private void  // ERROR: Handles clauses are not supported in C#
inactiveCustomersCheckBox_CheckedChanged(System.Object sender, System.EventArgs e)
    {
        // The Checked property of the inactiveCustomerCheckBox
        // has changed - repaint the customerDataGridView.
        this.customerDataGridView.Invalidate();
    }

    private void  // ERROR: Handles clauses are not supported in C#
orderOverdueCheckBox_CheckedChanged(System.Object sender, System.EventArgs e)
    {
        // The Checked property of the orderOverdueCheckBox
        // has changed - repaint the customerDataGridView.
        this.customerDataGridView.Invalidate();
    }


    private void  // ERROR: Handles clauses are not supported in C#
customerDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    {

        // If the column being formatted is the column named 'Status' ..
        if (this.customerDataGridView.Columns[e.ColumnIndex].Name == "Status") {
            if (e.Value != null) {
                // If the value of the cell is "Inactive" AND this form's inactiveCustomersCheckBox control is checked..
                if (e.Value.ToString == "Inactive" & this.inactiveCustomersCheckBox.Checked) {
                    // Set the BackColor of the cell to yellow.
                    e.CellStyle.BackColor = Color.Yellow;
                }
                if (e.Value.ToString == "Active" & this.activeCustomersCheckBox.Checked) {
                    // Set the BackColor of the cell to Fuchsia
                    e.CellStyle.BackColor = Color.Fuchsia;
                }
            }
        }

        // If the column being formatted is the column named 'LastOrderDate'..
        if (this.customerDataGridView.Columns(e.ColumnIndex).Name == "LastOrderDate") {
            if (e.Value != null) {
                // If LastOrderDate was more than 30 days ago AND this form's ordersOverdueCheckBox control is checked..
                if (System.DateTime.Now.Subtract((System.DateTime)e.Value).Days > 30 & this.orderOverdueCheckBox.Checked) {
                    // Set the BackColor of the cell to yellow-green.
                    e.CellStyle.BackColor = Color.YellowGreen;
                }
            }
        }
    }

    private void  // ERROR: Handles clauses are not supported in C#
activeCustomersCheckBox_CheckedChanged(System.Object sender, System.EventArgs e)
    {
        // The Checked property of the activeCustomerCheckBox
        // has changed - repaint the customerDataGridView.
        this.customerDataGridView.Invalidate();
    }
}


But, same code, when i tried to implement in Vb. The code is generating the output. I'm unable to correct this. So friends, please help me.

Regards
Indu. :doh:
Posted

1 solution

I haven't trawled through your code to look at what it's doing yet, but the immediate problem you're describing is caused by not adding the parenthesis to ToString to denote that it's a method call, i.e. e.Value.ToString().
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900