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
190
ultrawingrid cell validation in add/ edit mode
posted

Hi i am trying to validate entered cell value in ultrawingrid in add/edit mode. 

1) i want to check if cell value in empty in cell leave/row leave(if empty want to prompt a message)

2) want to check if the entered value is already exist in the grid , if exist want to prompt a message that already exist (i am using list<class> for databinding).

i have tried many ways but it's not complete;y working for all the scenario.

below are the code i am using for this.i am not which event is a appropriate to use.

  private voi grTest_BeforeExitEditMode(object sender, BeforeExitEditModeEventArgs e)

       {

  if (OriginalEmployeeList .Exists(element => element == name) == true)

                {

                    e.Cancel = true;

                    MessageBox.Show("Name (" + name + ") already exist");

                        activeCell.Activate();

                    grTest.PerformAction(UltraGridAction.EnterEditMode);

               }

                else {

                    OriginalEmployeeList = DataSource.Employee.EmployeeList.Select(r => r.EmployeeName).ToList();

                }

}

  private void grdDemandCenter_BeforeRowUpdate(object sender, CancelableRowEventArgs e)

        {

 if (OriginalEmployeeList .Exists(element => element == name) == true)

                {

                                   e.Cancel = true;

                    e.Row.DataErrorInfo.SetColumnError("Name", "Name already exist in the list");

                        e.Row.Cells["EmployeeName"].Activate();

                    grdEmployee.PerformAction(UltraGridAction.EnterEditMode);

                }

                else if (name == string.Empty)

                {

                    e.Cancel = true;

                    e.Row.DataErrorInfo.SetColumnError("Name", "Name cannot be empty");

                         grdEmployee.PerformAction(UltraGridAction.EnterEditMode);

                }

                else {

                    e.Row.DataErrorInfo.ClearErrors();

                    OriginalEmployeeList = DataSource.Employee.EmployeeList.Select(r => r.EmployeeName).ToList();

                    grdEmployee.PerformAction(UltraGridAction.ExitEditMode);

                }

}

 private void grdCustomer_InitializeRow(object sender, InitializeRowEventArgs e)

        {

} string s = e.Row.Cells[CustomerName"].Value.ToString();

            if (s == string.Empty)

            {

                e.Row.DataErrorInfo.SetColumnError("CustomerName", "Name cannot be empty");

}  else {

                //e.Row.DataErrorInfo.ResetRowError();

                e.Row.DataErrorInfo.ClearErrors();

            }

  • 469350
    Offline posted

    Hi,

    I'd be happy to help you with this, but I'm not sure exactly how I can be of assistance, since you didn't say exactly what the problem is. What exactly is "not working completely"?

    It seems like you should be able to achieve everything you want in the BeforeExitEditMode event. In that event, you know which cell is being edited (grid.ActiveCell) and so you can get the currently text of that cell using it's Text property. Bear in mind that this even fires BEFORE anything has been written to the data source, so if the current Text exists in the data source, then it may be a duplicate, but it's also possible that the value already exists in the SAME cell. So using the data source might not be a great way to do this. You will have to exclude the current row from your check for a duplicate value.

    Checking for a blank should be much simpler since it's just a single literal value you are looking for.

    The code you have here seems a bit of a mishmash. In BeforeExitEditMode, you are setting e.Cancel to true, which makes sense, but then there is no reason to call PerformAction(EnterEditMode), since the cell will never leave edit mode in the first place.

    Also, it's not clear to me why you are showing a MessageBox in some places and using SetColumnError in others. If you prevent the user from leaving the cell, then I can't see any reason to use SetColumnError.

    It would also be helpful to know the DataType of the column you are dealing with here.

    Maybe you could post a small sample project that demonstrates what you have so far and what isn't working and I could take a look and see if I can figure out why it's not working and offer some suggestions about how to improve it.