This is a migrated thread and some comments may be shown as answers.

Validation in a cell of RadGridview

0 Answers 245 Views
GridView
This is a migrated thread and some comments may be shown as answers.
rad
Top achievements
Rank 1
rad asked on 12 Sep 2011, 08:50 AM

Hi,

I am working with RadGridView, in MVVM WPF application and I need to validate cell compared to other values in binding collection.

I have a object :


public class MyObject
{
    public DateTime DateBegin { get; set;}
    public int Value { get; set;}
}

And if I add a new row in my GridView with existing Date I want to show error message in cell.

I thought to use an ValidationRules in my cell, but i am not sure if i can compared to with others values in binding list. I found some solution, but isn't MVVM compliant :

public void RadGridView1_CellValidating(object sender, GridViewCellValidatingEventArgs e)       {
            bool isValid = true;
            string validationText = "Validation failed. ";
            if(cell.column.uniquename == "mydatecolumn")
           {
            GridViewCell cell = e.Cell;
                    isValid = ValidateDate((datetime) e.NewValue);
                    if (!isValid)
                    {
                        validationText += "You already used that date, mate.";
                    }
           }
}
  
private static bool ValidateDate(datetime newDate)
        {
            // Some linq to see if it's in your collection or not
        }

Thanks

No answers yet. Maybe you can help?

Tags
GridView
Asked by
rad
Top achievements
Rank 1
Share this question
or