Rowvalidating event e.Cancel Hangs

I am using Rowvalidating event to validate and prevent user from moving out of the row unless the validation succeeds.

The code looks like below

if (dgdTelephones.Rows.Count > 0 && e.RowIndex < dgdTelephones.Rows.Count - 1)

{

if (dgdTelephones.IsCellNullOrEmpty("TelephoneType") ||

dgdTelephones.IsCellValueExists("TelephoneType") ||

dgdTelephones.IsCellNullOrEmpty("TelephoneNumber"))

{

e.Cancel =true;

}

}

I have 2 gridviews on the screen. This is one of them and has this event. When I move from this grid to any other control no issues, but when i move to the other grid, the system hangs. The processor is 100% used. Any idea whats happening. If I use the cell validating event it works fine, but i need to use the row validating event only.

If I remove the e.Cancel then it works but doesnt stop the row from moving

[1277 byte] By [Rohali] at [2007-12-24]
# 1
Need some more info to help you. What type of variable is dgdTelephones?
KenTucker at 2007-8-31 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 2

dgdTelephones is DataGridView .

When i use e.cancel to return true, the vhost.exe goes to 100% cpu.

This happens only when I move out of the Grid to another Grid when is not Readonly.

Rohali at 2007-8-31 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 3
There are not IsCellNullOrEmpty or IsCellValueExists methods for the datagridview. My guess is that you are using a control that inherits from the datagridview and there is a problem with one or both of those methods.
KenTucker at 2007-8-31 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 4
Ignore those methods. Even if I just have the e.cancel = true, it hangs.
Rohali at 2007-8-31 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 5

Just in case anyone else has this error, here is what I did for a similar situation. In the RowValidaing event of the dgv I placed the following:

if (this.datagridview.IsCurrentCellInEditMode)

e.Cancel = true;

That seemed to fix the problem.

steveareno at 2007-8-31 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...