2) Also, how can I make the respective control to be highlighted with red border when user clicks on any of the error?
6 Answers, 1 is accepted
Answer 1) I making use of custom validation and missed to specify second arguement to 'ValidationResult'
Second arguement should be the name of the property to be validated
Answer 2) Manual changed border color on SelectionChanged event of ValidationSummary
Firstly, specify the following attribute in Contract object:
[Required]
[CustomValidation(typeof(HelperClass.Validation), "IsValueSelected")]
[DataMember]
public string DropDownSelectItemID { get; set; }
Then in "HelperClass.Validation", do the following
namespace HelperClass
{
public static class Validation
{
public static ValidationResult IsValueSelected(this string selectedValue, ValidationContext validationContext)
{
if (selectedValue == "-1")
{
string[] memeberNames = new string[] { validationContext.MemberName };
switch (validationContext.MemberName)
{
case "DropDownSelectItemID":
return new ValidationResult("Please select a value from the drop down", memeberNames);
break;
}
}
else
{
return ValidationResult.Success;
}
}
}
}
Part 2) You need to just hook the selectionchanged event and change the border color
Thanks for your response. I was able to bind the combobox to to the datafield of dataform but the validation summary sees it as an object validation error and not as a property validation error which is why I have to find a way to set the combobox with red border color. The problem still remains that the order of the validation errors in the validation summary of the dataform doesn't show up in correct order as the elements on the Form when I have combination of comboboxes, checkboxes and textboxes. It seems to work correctly with textboxes only. The following questions still remains:
1) How do you set the tool tips with red background just like the tool tips appearing at the top right corner when validation fails for a textbox field?
2) How do you get the order of the errors to display correctly using validation summary when you have both property validation errors and object validation errors (from meta class for the object using RIA services,...)?
Vinh
1) I am not showing any tooltip on top-right corner of a combobox.
I am just setting the border color to red on selectionChanged event of ValidationSummary.
Maybe you need to google more on this task.
2) My issue of displaying order of errors was fixed by specifying
the second parameter to the function "ValidationResult()" as showh below
case "DropDownSelectItemID":
return new ValidationResult("Please select a value from the drop down", memeberNames);
break;
Maybe you can just remove second argument -> See the result -> Then apply second parameter -> See the result.
Might be you are implementing some other event which is causing above lines of code to not take effect.
My advice would be to concentrate on one task. Comment other lines of code related to ValidationSummary and proceed to step by step to correct order of display errors.
Thanks for your advice. I'll try to follow them and see how it turns out.