Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6579889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:57:18+00:00 2026-05-25T15:57:18+00:00

I have a datagridview with the following code: private void datagridview_CustomerList_CellEndEdit(object sender, DataGridViewCellEventArgs e)

  • 0

I have a datagridview with the following code:

    private void datagridview_CustomerList_CellEndEdit(object sender, DataGridViewCellEventArgs e)
    {
        if (!_continueCellEdit)
        {
            _continueCellEdit = true;
            return;
        }

        if (datagridview_CustomerList.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.Name == ColumnNames.NewRateColumn.ToString())
        {
            var row = datagridview_CustomerList.Rows[e.RowIndex];
            var font = datagridview_CustomerList.Font;

            if (modMain.SSS_ToDecimal(row.Cells[ColumnNames.NewRateColumn.ToString()].Value) > 0)
            {
                row.DefaultCellStyle.Font = new Font(font, FontStyle.Regular);
                if (modMain.SSS_ToDecimal(row.Cells[ColumnNames.BudgetBalanceColumn.ToString()].Value) > 0)
                    row.DefaultCellStyle.BackColor = color_BudgetCustomers;
                else
                    row.DefaultCellStyle.BackColor = color_OriginalColor;
            }
            else
            {
                row.DefaultCellStyle.BackColor = color_ZeroCharge;
                row.DefaultCellStyle.Font = new Font(font, FontStyle.Strikeout);
            }
        }

    }

    private void datagridview_CustomerList_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
    {
        _continueCellEdit = false;
        PaintRow(datagridview_CustomerList.Rows[e.RowIndex]);
    }

I am using the _continueCellEdit to prevent the CellEndEdit event from running. I can use this to disable/enable the event:

datagridview_CustomerList.CellEndEdit += datagridview_CustomerList_CellEndEdit;

This doesn’t help cause I don’t have a place to put the above line. If I put it in the datagridview_CustomerList_CellMouseDoubleClick it still runs after this event has finished.

I am prob overthinking this since I didn’t get to take lunch, I gotta blame something but…

Is there a better way of handling this instead of using a bool?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:57:19+00:00Added an answer on May 25, 2026 at 3:57 pm

    You could use the chain of responsibility pattern, but I honestly don’t think your use case warrants it and the bool solution is fine.

    That said it could be implemented something like this

    The first handler in the chain would basically look like

     public DoubliClickHanlder : IChain
     {
        public IChain NextHandler(get;set;)
    
     public void ProcessEvent(object sender, DataGridViewCellEventArgs e)
        {
          if !(this.continueCellEdit && this.NextHandler!= null)
              NextHandler.ProcessEvent(sender,e) 
        }
    
     }
    

    and the second handler would look like

    public GridColorSetter : IChain
    {
     public IChain NextHandler(get;set;)
    public void ProcessEvent(object sender, DataGridViewCellEventArgs e)
    {
           if (datagridview_CustomerList.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.Name == ColumnNames.NewRateColumn.ToString())
            {
                var row = datagridview_CustomerList.Rows[e.RowIndex];
                var font = datagridview_CustomerList.Font;
    
                if (modMain.SSS_ToDecimal(row.Cells[ColumnNames.NewRateColumn.ToString()].Value) > 0)
                {
                    row.DefaultCellStyle.Font = new Font(font, FontStyle.Regular);
                    if (modMain.SSS_ToDecimal(row.Cells[ColumnNames.BudgetBalanceColumn.ToString()].Value) > 0)
                        row.DefaultCellStyle.BackColor = color_BudgetCustomers;
                    else
                        row.DefaultCellStyle.BackColor = color_OriginalColor;
                }
                else
                {
                    row.DefaultCellStyle.BackColor = color_ZeroCharge;
                    row.DefaultCellStyle.Font = new Font(font, FontStyle.Strikeout);
                }
            }
    
        if (this.NextHandler!= null)
          this.NextHandler.ProcessEvent;
    
     }
    }
    }
    

    Then it you could write the following

    DoubleClickHandler dch = new DoubleClickHandler () {NextHandler= new GridColorSetter()}
    this.datagridview_CustomerList.CellEndEdit += dch.ProcessEvent;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: private void button1_Click(object sender, EventArgs e) { var answer
The following code is used to populate a DGV: private void frmSwitch_Load(object sender, EventArgs
I have a Dictionary bound to DataGridView by using following sample code. DataGridView bound
I have the following code: public void DriveRecursion(string retPath) { string pattern = @[~#&!%\+\{\}]+;
With a listbox, I have the following code to extract the item selected: private
I have following code for 3 DataGridView Controls in my VB.NET winform application. How
I have the following code in a WinForms datagridview for handling right-mouse-clicks to select
I have the following code that should loop through all the rows in my
i have the following code.... For Each dgvRow In bout_grid.Rows vfile = dgvRow.Cells(FileName).Value video.FileName
I have the following code but the DatGridView is showing me empty rows. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.