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