Block Cell validation in Close Button

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
hi,
I have form in windows Form application which contains grid view. The grid have cell validating event so every incorrect entry shows error. My problem is when the user focus the cell but thinks that not need to continue. So he needs to click close button
and exit the form. But cell validating create problem here. Can anyone give advise on this?
Now i got a work around like overriding wndproc so that i update one bool variable based on the message and control the cell validating event. This is working fine if i click close button (x) in the form. But i need to control same mechanism in my Close
button in the form. I set forms cancel button as my close button
The existing code is
<pre class="prettyprint private void dgv_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if (_exit) return;
//Validation logic here
}


protected override void WndProc(ref Message m)
{
if (m.Msg == 0x10) _exit = true; // Trap WM_CLOSE
base.WndProc(ref m);
}[/code]
Can anyone help on this to achieve in close button also<br/>


View the full article
 
Back
Top