Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
225
WinGrid : problems with BeforeExitEditMode event
posted

Hello. I have splitter control with 2 panels (top and bottom). So bottom panel contains UltraGridControl (ultraGrid1). So I enter edit mode and type smth in a cell and then click the top panel.  I have BeforeExitEditMode handler like this

private void ultraGrid1_BeforeExitEditMode

{

    if (MyCondition)

         e.Cancel = true;

}

So

1) I enter in edit mode and type smth. ( MyCondition == true )

2) After that I select the second tab and it become active.

I can't understand: why it is possible to leave grid when I set e.Cancel = true. In this case what is event "BeforeExitEditMode" for ???

The second problem: if I try to use message box for displaying error it brings to infinity loop:

if (MyCondition)

{

        MessageBox.Show("Error!!!");

         e.Cancel = true;

}

Could somebody explain this strange behavior to me? Waiting for reply.

Thanks.

 

  • 469350
    Verified Answer
    Offline posted

     

    Shmel said:
    I can't understand: why it is possible to leave grid when I set e.Cancel = true. In this case what is event "BeforeExitEditMode" for ???

    My guess is that the tab control is not taking focus. Since it doesn't get focus, it is never activated and thus the grid cell never exit's edit mode when you switch tabs. If you are using UltraTab, you might want to handle BeforeSelectedTabChanged and call PerformAction(ExitEditMode) on the grid and if it fails, cancel the switching of tabs. 

    Shmel said:
    The second problem: if I try to use message box for displaying error it brings to infinity loop:

    Showing a MessageBox will force the cell to exit edit mode, because unlike the tab control, the MessageBox DOES take focus. So the cell is already about to exit edit mode, you show a MessageBox which forces it to exit edit mode, which fires BeforeExitEditMode, which shows a Messagebox, which forces the cell to exit edit mode, etc. Basically, you can't show a MessageBox in this event.