Master
Master

Reputation: 2153

How To Trigger RowEditEnded Programatically For a Grid

Hi I have two controls present. The first one is a Datepicker with the name Disbursal. The second one is a Grid with multiple columns but the only column that matter is the Date Column.

How the validation works at the moment is if I move the date within the grid, if it's before the disbursal date, there's a validation check upon RowEditEnded.

I would like to do the reverse as well now. If the disbursal date is changed, I would like the validation for each row that exist in the grid to trigger.

So my question is, upon Disbursal Datepicker selection change, how do i iterate through the rows and have each row enter edit and end edit so the validations will trigger.

this.RadGridView1.RowEditEnded += this.radGridView_RowEditEnded;
this.RadGridView1.BeginningEdit += this.radGridView_BeginningEdit;

private void radGridView_BeginningEdit(object sender, GridViewBeginningEditRoutedEventArgs e)
{
    ((ScriptDTO)e.Cell.DataContext).ClearErrors();
}

private void radGridView_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)
{
    if (e.EditAction == GridViewEditAction.Commit)
    {
        ScriptDTO editedPerson = e.Row.DataContext as ScriptDTO;
        if (editedPerson.Date <= DisbursalDatePicker.SelectedDate)
        {
            editedPerson.SetError("Date", "Must be after disbursal");
        }
        else
        {
            editedPerson.ClearErrors();
        }
    }
}

Upvotes: 0

Views: 107

Answers (1)

mm8
mm8

Reputation: 169150

You could iterate through the items in the Items collection of the RadGridView:

private void DisbursalDatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
{
    foreach (ScriptDTO person in RadGridView1.Items.OfType<ScriptDTO>())
    {
        if (person.Date <= DisbursalDatePicker.SelectedDate)
        {
            person.SetError("Date", "Must be after disbursal");
        }
        else
        {
            person.ClearErrors();
        }
    }
}

Don't bother about trying to raise the actual RowEditEnded event programmatically.

Upvotes: 1

Related Questions