Hi I am having a telerik GridView in my WPF application. In that grid i am having three columns like Number, Max and Min. Now I need to disable the Min and Max Cells When i will give some value on the Number column for a selected row.
I declared two variables like MaxCell and MinCell as GridViewCellBase. If The Query(Mentioned below for Getting MaxCell and MinCell) will return null value, I am not able to give IsEnabled as False. Its not accepting any value . Its giving Null reference Exception.
How can i solve this problem ? can any Please tell me the solution of this problem? Thanks in Advance.
foreach (GridViewCell cell in row.Cells)
{
if (cell.Column.Header.ToString() == "Number" && Convert.ToInt32 (cell.Value) > 0)
{
GridViewCellBase MaxCell = new GridViewCellBase();
GridViewCellBase MinCell=new GridViewCellBase();
MaxCell=(from c in row.Cells
where c.Column.Name == "Max"
select c).FirstOrDefault();
MinCell =(from c in row.Cells
where c.Column.Name == "Min"
select c).FirstOrDefault();
MaxCell.IsEnabled = false;// Here I am getting the null reference exception when MaxCell and MinCell having empty values
MinCell.IsEnabled = false;
break;
}
}
The MaxCell always returning empty value only. So i cant give the IsEnabled property. Now my doubt is, Why the MaxCell value is always coming as empty or null value? The cells are having the column like “Max” and “Min”. Then it should return the Actual Cell but Why its always returning null value?
Instead of using approach you’ve described. I would try modifying cell style of particular columns and create a binding on IsEnabled property with converter that is returning appropriate value.
Then Apply this style to specific columns as fallows:
If you don’t like this you can always use triggers.