C# WinForm-Datagrid Validating Event

I have a C# Windows form with a datagrid control. There is a Validating event on the datagrid that checks for changes:
  if (this.dsAccts1.HasChanges() == true)
  {
    if (MessageBox.Show("Do you want to save your changes?",
            "Save",
            System.Windows.Forms.MessageBoxButtons.YesNo,
            MessageBoxIcon.Question,MessageBoxDefaultButton.Button1)
      == System.Windows.Forms.DialogResult.Yes)
      {
           e.Cancel = true;
      }
      else
      {
          //do nothing for now
      }
  }

When I update the value of a cell, move to a next record, then scroll, the Validating event is firing when that updated cell scrolls off of the datagrid's visible area.
I have also noticed that when using the mouse scroll wheel, the grid stops scrolling when the active record leave the viewable area.
QUESTION: How do I prevent the Validating event from firing while I scroll the grid???
LVL 11
Jokra_the_BarbarianAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mmarinovCommented:
Hi Jokra_the_Barbarian,

here is the remarks from the msdn about validating event
Remarks
When you change the focus by using the keyboard (TAB, SHIFT+TAB, and so on), by calling the Select or SelectNextControl methods, or by setting the ContainerControl.ActiveControl property to the current form, focus events occur in the following order:

Enter
GotFocus
Leave
Validating
Validated
LostFocus
When you change the focus by using the mouse or by calling the Focus method, focus events occur in the following order:

Enter
GotFocus
LostFocus
Leave
Validating
Validated
If the CausesValidation property is set to false, the Validating and Validated events are suppressed.

If the Cancel property of the CancelEventArgs object is set to true in the Validating event delegate, all events that would normally occur after the Validating event are suppressed.


i think that set causesvalidation=false and at the end set it to true ( before update ) is the best choise

B..M
0
Jokra_the_BarbarianAuthor Commented:
Thank you B..M for your response. I don't think it is related to the Validation as it is the record moving off the viewable area of the datagrid. I found some code on windowsforms.net that takes care of the mouse wheel:
--------------------------------
  myDataGrid.MouseWheel += new MouseEventHandler(myDataGrid_MouseWheel);

then:

  private void myDataGrid_MouseWheel(object sender, MouseEventArgs e)
  {
  myDataGrid.Select();
  }
--------------------------------

I'm attempting to add an event handler for the datagrid's scroll, but with the following code I'm getting an error:
 
  this.dgGLAccts.Scroll += new System.Windows.Forms.ScrollEventHandler(myDataGrid_ScrollBar);

ERROR: Cannot implicitly convert type 'System.Windows.Forms.ScrollEventHandler' to 'System.EventHandler'

Any ideas?
0
mmarinovCommented:
Jokra_the_Barbarian,


it must be
this.dgGLAccts.Scroll += new EventHandler(myDataGrid_ScrollBar);


B..M
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jokra_the_BarbarianAuthor Commented:
B..M, thanks for your help. I'll give that EventHandler a try tomorrow.  -Jokra
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

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.