Posted 14 Feb 2012 Link to this post
private
void
myGrid_CellValidating(
object
sender, GridViewCellValidatingEventArgs e)
{
fooEntity selectedEntity = e.Row.Column[1].CurrentItem
as
fooEntity; //How to do this??
//How to do this??
if
(e.Cell.Column.UniqueName ==
"validateThisColumn"
)
(e.NewValue.ToString()== selectedEntity.SomeProperty)
e.IsValid =
false
;
e.ErrorMessage =
"No way!"
}
Posted 15 Feb 2012 Link to this post
Basically, during CellValidating event you can get the current item from the grid and it would be of the same type (you will find the selected item from the source of the grid). Getting the item from the source of GridViewComboBoxColumn will require some additional logic - to get the property for the corresponding column and find the corresponding item from the source of the column. Could you clarify which item exactly do you want to get - the one from the grid or the one from the column ?
ProjectMetricChildGrid_RowValidating(
sender, GridViewRowValidatingEventArgs e)
GridViewRow validatingRow = e.Row;
RadComboBox projectSubjectCmb = validatingRow.ChildrenOfType<RadComboBox>().FirstOrDefault();
//projectSubjectCmb is always null
fooEntity selectedFoo = projectSubjectCmb.SelectedItem
fooEntity;
//my validation logic continues.....
Posted 16 Feb 2012 Link to this post
Actually, that would be the expected behavior since during RowValidating event the row is getting out of edit mode and the editing element of GridViewComboBoxColumn (RadComboBox) is hidden. What you can try is to find the element in the source of the column that corresponds to the property from the source of the grid. I am attaching a sample project so that you can test the suggested approach. Could you take a look at it and let me know whether it corresponds to your requirements ?
Posted 17 Feb 2012 Link to this post
I am happy to see that the suggested approach fits into your requirements. Let me know in case you need further assistance.