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
480
when to validate a grid cell?
posted

I have popup dialog the contains a datagrid and two buttons Ok and Cancel. 

I would like the data grid to validate the cells as the user edits the cells.

When a user enters a value, I validate the cell value on leaving the edit mode.   If the cell is in a bad state, the exit edit mode event cancel flag is set true 

void Grid_BeforeExitEditMode(object sender, Infragistics.Win.UltraWinGrid.BeforeExitEditModeEventArgs e)
{

 UltraGrid grid = (UltraGrid)sender;
 UltraGridCell activeCell = grid.ActiveCell;
 if (activeCell.Column == columnWithRules)
{
    string valStr = activeCell.Text;
    valStr = valStr.Trim();

    if (!checkRules(valStr))
   {

        e.Cancel = true;
      WarningPopup.Show(grid, "bad value");
     }
   }
}

This works well when the user enters text into cells,  enter and exits edit mode, as they click other grid cells.  

However, the work flow is broken when the user hits the 'Cancel' button for the entire dialog. 

The issue is that the user can enter value by keyboard,  perhaps an bad value in a grid cell.   
Then the user simply mouse clicks the cancel button for the whole dialog while the cell is STILL in edit mode. 

Since the grid leaves the edit mode when it loses focus, the validation is performed on the bad cell.  The  exit edit mode event happens prior to the 'Cancel' button receiving events.

The order of events make it hard  to both validate per cell edits and permit a 'Cancel' button on the whole dialog. 

Is there way to accommodate both work flows?

Parents
No Data
Reply
  • 21795
    Offline posted

    Hello Karl,

    What you can do in this case is add some Boolean flag showing if the mouse is within the grid. You can set this flag to true when mouse enters the grid and set it to false when mouse leave the grid. Then change your BeforeExitEditMode handler like this:

    void Grid_BeforeExitEditMode(object sender, Infragistics.Win.UltraWinGrid.BeforeExitEditModeEventArgs e)
    {
        UltraGrid grid = (UltraGrid)sender;
        UltraGridCell activeCell = grid.ActiveCell;
        if(activeCell.Column == columnWithRules)
        {
            string valStr = activeCell.Text;
            valStr = valStr.Trim();
     
            if(!checkRules(valStr) && this.mouseIsOnGrid == true)
            {
     
                e.Cancel = true;
                WarningPopup.Show(grid, "bad value");
            }
        }
    }

    This way the WarningPopup will never show if the mouse cursor is outside of the grid. Note, you should handle what should happen if end user puts the cell in edit mode and then clicks on some other control but the grid.

    Please let me know if you have any additional questions.

Children