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

Property editor displays a dialog

11 Answers 336 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
FRANCISCO C P RODRIGUES
Top achievements
Rank 1
FRANCISCO C P RODRIGUES asked on 14 Jun 2012, 11:10 PM
Hi,

Is there any way to define a dialog as the editor associated with a property (for example like the one displayed for the Telerik.WinControls.UI.RadTreeView.Nodes by Visual Studio)?

I have some properties that are way too complex for the user and I would like to display a dialog to help them edit those properties.

Thanks,

Francisco

11 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 19 Jun 2012, 07:51 AM
Hello Francisco,

Thank you for writing.

One possible way to achieve the desired behavior is to add a button to the text box editor and upon click, open the desired form. Attached you can find a sample project demonstrating this. Alternatively, you can create your own editor and use it for the desired functionality. Information regarding custom editors in RadPropertyGrid can be found here: http://www.telerik.com/help/winforms/propertygrid-editors-using-custom-editor.html 

I hope this helps. Let us know if you have any other questions.
 
Kind regards,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
FRANCISCO C P RODRIGUES
Top achievements
Rank 1
answered on 19 Jun 2012, 01:02 PM
Stefan,

Thank you for your answer.

I think you forgot to attach the sample project; I couldn't find it anywhere.

I tried a different approach, creating an editor that returns a "RadBrowseEditorElement". My idea was to replace the "CLICK" event of the button and instead of displaying the default control dialog, display a personalized dialog. The problem with this aproach is that I don't known when the "CLICK" event is set internally and, because of that, I could not replace this event with my own.

I would like this oportunity to make a suggestion: it woul be great if you guys could turn the "RadBrowseEditorElement" in a more generic control so that we can use it to display our own dialogs (for example publishing an event associated with the button so that we can use this event to display the mentioned dialogs).

Thanks,

Francisco
0
Stefan
Telerik team
answered on 20 Jun 2012, 05:26 AM
Hello Francisco,

Please excuse me for the omission. The file is now attached.

Thanks to our TPF, creating such a customization is not a hard task. One possible way is demonstrated in the attached project.

Let me know how this approach works for you.

All the best,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
FRANCISCO C P RODRIGUES
Top achievements
Rank 1
answered on 22 Jun 2012, 02:43 PM
Stefan,

The suggested  approach is ok but I found a problem. Once the property with the "special textbox editor" is selected, all other properties that use a "text box editor" will also display the "special text box" (see the attached images).

Can you help me with this?

Thanks,

Francisco
0
Ivan Petrov
Telerik team
answered on 25 Jun 2012, 04:13 PM
Hello Francisco,

Thank you for writing back.

This is happening because of the editor caching mechanism in RadPropertyGrid. This mechanism caches editors in order to speed up the editing process. In this case the easier approach appears to be the custom editor. I have modified the example project so the property grid would use a special editor for the complex property and all other properties would be edited with the default one.

I hope this will be useful. If you have further questions, I would be glad to help.

Greetings,
Ivan Petrov
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Timo
Top achievements
Rank 1
answered on 23 Aug 2013, 11:28 AM
Hi,

I created a custom editor based on Ivan's example where user can edit the value in a RichTextBox.
If dialog returns DialogResult.OK then I assign RichTextBox.Text to the property Value.
Sometimes the new value is updated but mostly the value isn't changed.

Do you have an idea what I missed ?

Thanks in advance!
Timo
0
Ivan Petrov
Telerik team
answered on 28 Aug 2013, 08:18 AM
Hi Timo,

Thank you for writing.

I have modified the example project from my previous post to replicate the scenario you have described. I was not able to reproduce the issue you have described. I would kindly ask you to review the project and check if there are any differences with yours.

Looking forward to your reply.

Regards,
Ivan Petrov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Timo
Top achievements
Rank 1
answered on 29 Aug 2013, 07:16 AM
Hi Ivan,

thanks for your help. It was quite easy, only update to Telerik Controls 2012.3.1211 and my problem disappeared :-)

Thanks
Timo
0
Larry
Top achievements
Rank 2
answered on 06 Jun 2014, 01:54 PM
I am using your example on a property in the RadPropertyGrid called "Email".  The example works great, but I want to be able to retrieve the email address that is in the property and generate an email.  I have tried to find the value in the element and the textBoxItem of CreateEditorElement, but cannot locate where the value for the property is stored.  I have converted your code to VB and attached it to this message.

Protected Overrides Function CreateEditorElement() As Telerik.WinControls.RadElement
 
        Dim element As Telerik.WinControls.UI.BaseTextBoxEditorElement = TryCast(MyBase.CreateEditorElement(), Telerik.WinControls.UI.BaseTextBoxEditorElement)
        Dim textBoxItem As Telerik.WinControls.UI.RadTextBoxItem = element.TextBoxItem
 
        If element.Children.Contains(textBoxItem) Then
            Dim button As New Telerik.WinControls.UI.RadButtonElement()
            button.Text = "Open Outlook"
            AddHandler button.Click, AddressOf button_Click
 
            textBoxItem.Alignment = ContentAlignment.MiddleLeft
            element.Children.Remove(textBoxItem)
 
            Telerik.WinControls.Layouts.DockLayoutPanel.SetDock(textBoxItem, Telerik.WinControls.Layouts.Dock.Left)
            Telerik.WinControls.Layouts.DockLayoutPanel.SetDock(button, Telerik.WinControls.Layouts.Dock.Right)
 
            Dim dockLayoutPanel__1 As New Telerik.WinControls.Layouts.DockLayoutPanel()
 
            dockLayoutPanel__1.Children.Add(button)
            dockLayoutPanel__1.Children.Add(textBoxItem)
 
            element.Children.Add(dockLayoutPanel__1)
        End If
 
        Return element
    End Function
0
Larry
Top achievements
Rank 2
answered on 06 Jun 2014, 02:05 PM
Never mind.  I was looking in the wrong place.  I should have been looking in the button_Click event. The following is an example of how to find the value of the property.

Private Sub button_Click(sender As Object, e As EventArgs)
 
    Dim rtxtboxitem As Telerik.WinControls.UI.RadTextBoxItem = _
        CType(sender, Telerik.WinControls.UI.RadButtonElement).Parent.Children(1)
 
End Sub
0
Ivan Petrov
Telerik team
answered on 11 Jun 2014, 09:33 AM
Hello Larry,

Thank you for writing.

Although sometimes unavoidable we strive to minimize as much as possible the use of code like Parent.Parent and Children(0).Children(2). This makes the code really unreadable and also makes it more difficult to maintain. Here are several options you have for retrieving the property value from within the button click event handler, depending on the type of the property:
1. If the property is a string you can directly access it through Me.Value, where Me would be the CustomTextBoxEditor. Me.Value returns a string boxed in an object so you will have to cast it.
2. Me.TextBoxEditorElement.Text would give you the text displayed in the editor text box.
3. If the email property is some complex object you can retrieve it like this:
Dim itemElement As PropertyGridItemElement = TryCast(Me.OwnerElement, PropertyGridItemElement)
Dim item As PropertyGridItem = TryCast(itemElement.Data, PropertyGridItem)
Dim mail As Email = TryCast(item.Value, Email)

I hope this will help. Do not hesitate to contact us with further questions.

Regards,
Ivan Petrov
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
PropertyGrid
Asked by
FRANCISCO C P RODRIGUES
Top achievements
Rank 1
Answers by
Stefan
Telerik team
FRANCISCO C P RODRIGUES
Top achievements
Rank 1
Ivan Petrov
Telerik team
Timo
Top achievements
Rank 1
Larry
Top achievements
Rank 2
Share this question
or