Quantcast
Channel: wpftoolkit Discussions Rss Feed
Viewing all articles
Browse latest Browse all 2157

New Post: How to set focus on the desired PropertyItem of a PropertyGrid manually in code Behind

$
0
0
Hi,
I implemented a validation system for my propertyGrid's model and i want to put the focus on the current propertyItem having errors for the user correct it.

Here my function :
private string _message  = "";
        private bool ValidateProperties(PropertyItemCollection pProperties)
        {
            bool isExpandedState = false;
            foreach (var property in pProperties)
            {
                if (Validation.GetHasError(property))
                {
                    foreach (var error in Validation.GetErrors(property))
                    {
                        _message += error.ErrorContent.ToString() + "\n";
                    }
                    //_message = Validation.GetErrors(prop)[0].ErrorContent.ToString();
                    property.IsSelected = true;
                    property.Focusable = true;
                    property.Focus();
                    return false;
                }
                else if (property.IsExpandable)
                {
                    isExpandedState = property.IsExpanded;
                    property.IsExpanded = true;
                    if (!ValidateProperties(property.Properties))
                        return false;
                    else
                        property.IsExpanded = isExpandedState;
                }
            }
            return true;
        }
property.Focusable = true and property.Focus() doesn't work.

Thank you for your help.

Viewing all articles
Browse latest Browse all 2157

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>