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

Combobox row via DataTemplateSelector, how to detect when they should be disabled?

4 Answers 128 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 23 Dec 2011, 05:23 PM
Hi all,

I've made the first row of my grid contain comboboxes using a DataTemplateSelector. This works like a charm.

My problem is associated with validation errors when they occur in a cell in a different row. When a cell fails to validate, the cells in the rest of the grid become readonly and non-focusable, or disabled in some fashion, so the focus cannot be changed to a different cell in the grid. However, the comboboxes remain enabled. I want to disable them but cannot find a property in the tree above them to bind to.

I am trying to use something like:

const string xaml =
      "<DataTemplate>"
    + "<ComboBox Tag=\"{0}\" IsEnabled=\"{{Binding Path=IsEnabled, RelativeSource={{RelativeSource FindAncestor, AncestorType=telerik:GridViewCell}}}}\" />"
    + "</DataTemplate>";
string dataTemplateXaml = string.Format(xaml, fieldIndex);

In this example, I am looking to the IsEnabled property on the enclosing GridViewCell but it does not work. I've used Snoop to walk up the tree to the RadGridView to find a property to which I can bind to get the correct behavior. I cannot find a property that changes when there is a validation error in a cell in the grid.

Maybe I'm way off base on this approach. Suggestions would be greatly appreciated.

4 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 28 Dec 2011, 09:07 AM
Hi Scott,

Generally you are looking for GridViewCell.IsValid property (this property changes its value when there is a validation error). I cannot give you any suggestion with the provided information. Could you please send me a little bit more information about your scenario?

Greetings,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Scott
Top achievements
Rank 1
answered on 28 Dec 2011, 07:39 PM
HI Nedyalko,

I have used a template selector to put comboboxes in the first row of a grid as shown in the attached image. What I've done here is to duplicate the name of an item in two columns and tried to tab out. The validation logic catches this fact and signals the error.

With the exception of my row, I cannot change the focus to any other cell in the grid. However, in my row with the comboboxes, the controls are still enabled. You should be able to reproduce this with any standard control, e.g., someone putting in a validating text box would have the same problem.

My guess is that there is a property somewhere, possibly at the grid level, that tells all other cells that they cannot get the focus when an error exists in a cell somewhere else in the grid.

The workaround that I see is to put a property in the ViewModel that is set from my code behind when a validation error exists and is watched by my comboboxes. Rather than me going through extraordinary effort to ensure that I can track the validation errors in the grid, I should be able to watch some property on the grid and set the IsEnabled property on the comboboxes.

I am guessing that there is no such property, such that controls in row 1 can know that there is a validation error in row 2.
 
Does that explanation make sense?

Thanks
0
Nedyalko Nikolov
Telerik team
answered on 29 Dec 2011, 09:37 AM
Hi,

Indeed this is the default behavior when there is "invalid" cell no other cell could get the focus. You can try setting RadGridView.ValidatesOnDataErrors = "InViewMode" (the default value is InViewMode + InEditMode). This will show red borders around "invalid" cells only in view mode and you will be able to focus another cells. This approach will work only if validation is done by DataAnnotation attributes or using IDataErrorInfo interface. If this does not help, please send me a sample project which I can debug on my side I'll be glad to assist.

Regards,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Scott
Top achievements
Rank 1
answered on 29 Dec 2011, 01:54 PM
Thank you for the reply, Nedyalko.

It will take me a little while to digest what you have suggested. If that doesn't get me there, I will post again.
Tags
GridView
Asked by
Scott
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Scott
Top achievements
Rank 1
Share this question
or