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

Editor validation and PropertyGrid

1 Answer 122 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 19 Aug 2012, 05:13 PM
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,
        StringComparison.CurrentCultureIgnoreCase))
    {
        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?

1 Answer, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 22 Aug 2012, 01:35 PM
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 >>
Tags
General Discussions
Asked by
Michael
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Share this question
or