[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

C# WinForm-Datagrid Validating Event

Posted on 2004-10-22
4
Medium Priority
?
4,717 Views
Last Modified: 2012-06-21
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???
0
Comment
Question by:Jokra_the_Barbarian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 28

Expert Comment

by:mmarinov
ID: 12385685
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
 
LVL 11

Author Comment

by:Jokra_the_Barbarian
ID: 12385827
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
 
LVL 28

Accepted Solution

by:
mmarinov earned 957 total points
ID: 12385854
Jokra_the_Barbarian,


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


B..M
0
 
LVL 11

Author Comment

by:Jokra_the_Barbarian
ID: 12386779
B..M, thanks for your help. I'll give that EventHandler a try tomorrow.  -Jokra
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

650 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