Editor validation and PropertyGrid

2 posts, 0 answers
  1. Michael
    Michael avatar
    14 posts
    Member since:
    Jun 2012

    Posted 19 Aug 2012 Link to this post

    I think this is more of an editor question than it is a PropertyGrid question, but here goes.

    I've got some domain objects that I adapt into a PropertyGrid SelectedObject. The adapter isn't "much" more than adapted getters/setters wrapping the domain objects. With me so far? Good...

    For some properties, I've built in INotifyBeforePropertyChanges, INotifyPropertyChanged, and INotifyAfterPropertyChanged interfaces, the .NET one is INotifyPropertyChanged, with the others doing the expected type operations.

    In application, my domain objects have a Name, which I want to intercept and preclude duplicate names. Enter editor validations. It doesn't matter to me whether control over the editing is through the validations or we can utilize our property interfaces. Matters not.

    I do have the BeforePropertyChanges event being handled at present. I look out to a list control and/or database for duplicate names and prompt the user when that's the case.

    I'd like to do that through the PropertyGrid editor if possible: here's the code snippet setting that up.

    private void PropertyGrid_EditorInitialized(object sender, PropertyGridItemEditorInitializedEventArgs e)
        Debug.Assert(e.Item is PropertyGridItem);
        var __e_Item = e.Item as PropertyGridItem;
        if (__e_Item.Name.Equals(DataSourcePropertyGridNames.Name,
            Debug.Assert(e.Editor is BaseTextBoxEditor);
            var __e_Editor = e.Editor as BaseTextBoxEditor;
            //TODO: Implement this and examine sender (I think).
            __e_Editor.Validating += PropertyGrid_Name_Editor_Validating;

    However, the event doesn't seem to go at all. I think because my domain object event is getting in the way.

    Edit: I've verified, the event is being hooked up, although it is a PropertyGridTextEditor and not BaseTextBoxEditor, which might have something to do with it. Event doesn't get dispatched.

    Edit: Still doesn't go.

    Can you confirm that the Validating event works?
  2. Ivan Petrov
    Ivan Petrov avatar
    701 posts

    Posted 22 Aug 2012 Link to this post

    Hi Michael,

    Thank you for writing.

    It is advisable to use RadPropertyGird's PropertyValidating and PropertyValidated properties. They are designed for validating the editing of properties. This will also save you the effort to subscribe and validate all types of editors separately.

    I hope this will help. If you need further assistance, I would be glad to help.
    All the best,
    Ivan Petrov
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  3. DevCraft R3 2016 release webinar banner
Back to Top