custom editor

20 posts, 1 answers
  1. Mehdi
    Mehdi avatar
    4 posts
    Member since:
    Mar 2013

    Posted 16 Mar 2013 Link to this post

    hi
    i have a class with some property and one of the properties is another class
    and i want to show a button in property grid and after click the button show the custom form
    for editing the property
    can anyone help please?

    i am useig Telerik Q1 2012 and .net 2.
    thanks.
  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 20 Mar 2013 Link to this post

    Hi,

    Thank you for writing.

    If I understand correctly, you need to show a custom editor for editing a certain property. The correct place to do so is the EditorRequired event of the control. Here you can find an example: http://www.telerik.com/help/winforms/propertygrid-editors-using-custom-editor.html.

    I hope this helps.
     

    All the best,
    Stefan
    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Mehdi
    Mehdi avatar
    4 posts
    Member since:
    Mar 2013

    Posted 28 Mar 2013 Link to this post

    thanks for answer
    i saw this example earlier but my situation is different
    i write here a class example 
    and in the editor i have to make editor like a button
    this is for example my class and i want to show a button  and after click the button show Form1 for edit 

        class Class1
        {
            public int W { get; set; }
            public int H { get; set; }
            public Form1 Form1 { get; set; }

            public Class1()
            {
                W = 10;
                H = 20;
                Form1 = new Form1();
            }
        }
  5. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 01 Apr 2013 Link to this post

    Hello,

    Thank you for writing back.

    I think that this is exactly what you need - you have a class with some property and you want to display a button to show a form where you can edit its values. In order to display this button, you would need to create a custom editor as demonstrated in the example previously provided. Here is a sample implementation to get you started:
    public class PropertyGridButtonEditor : BaseInputEditor
         {
             public override object Value
             {
                 get
                 {
                     return null;
                 }
                 set
                 {
           
                 }
             }
     
             public override Type DataType
             {
                 get { return typeof(Form1); }
             }
     
             RadButtonElement button = new RadButtonElement();
     
             public override void BeginEdit()
             {
                 base.BeginEdit();
     
                 this.EditorElement.Focus();
                 button.Click += el_Click;
             }
     
             public override bool EndEdit()
             {
                 button.Click -= el_Click;
                 return base.EndEdit();
             }
     
             protected override RadElement CreateEditorElement()
             {
                 button.Text = "Press to open custom form";
                 return button;
             }
     
             void el_Click(object sender, EventArgs e)
             {
                 RadMessageBox.Show("this is your form");
             }
         }

    and here is how to put your custom editor in action: 
    void radPropertyGrid1_EditorRequired(object sender, PropertyGridEditorRequiredEventArgs e)
           {
               if (e.Item.Label == "Form1")
               {
                   e.EditorType = typeof(PropertyGridButtonEditor);
               }
           }

    I hope this helps.

    All the best,
    Stefan
    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
  6. Mehdi
    Mehdi avatar
    4 posts
    Member since:
    Mar 2013

    Posted 03 Apr 2013 Link to this post

    thanks  it worked.
    but there is some thing
    when i run the program and check the property it is not look like a button because we change the property type in editor required event
    i tried to use code in editor initialized event but didn't work
    and also tried to change type of my property in property store that i use. this is also didn't work 
    any solution?
    thanks.
  7. Answer
    Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 05 Apr 2013 Link to this post

    Hi,

    The editor for some property will be displayed only when you double click or start typing in the cell and this is why you cannot see the button before that.

    To display the button at all times, you need to create a custom property grid item. Attached you can find a sample project demonstrating that.

    I hope this helps.
     

    Regards,
    Stefan
    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
  8. Mehdi
    Mehdi avatar
    4 posts
    Member since:
    Mar 2013

    Posted 13 Apr 2013 Link to this post

    hi and thanks.
    it worked perfectly.
  9. Brian
    Brian avatar
    24 posts
    Member since:
    Apr 2008

    Posted 15 Aug 2013 Link to this post

    Hi,

    I have modified your code by adding the custom editor to several items in the property grid.


    But the editors are not displayed correct when scrolling the property grid.

    ScreenDump1 displays the initial correct position. ScreenDump2 displays the wrong position after scroll.

    Do you have a work around?

    /Brian

  10. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 19 Aug 2013 Link to this post

    Hello Brian,

    Thank you for writing.

    The observed behavior is expected and is caused by the UI virtualization of the control. What happens during scrolling is that when a new item is being added, it checks the cached items (the ones that are no longer visible, if such) and if it finds a match between them it reuses it. While looking for an item, if it finds a standard item (PropertyGridItemElement) in the cache, it will report that it is compatible with all types of items besides bool and color and it will reuse it. 

    To overcome this behavior, you would have to create a standard item as well and in its IsCompatible override, return whether or not it is compatible with your item. Attached you can find the modified version of the project, where is the standard item, I am declaring that it is not compatible with an item named "SpecialText", hence the standard item is not used for this kind of items and the custom item will be used instead.

    I hope this helps.
     

    Regards,
    Stefan
    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 >>
  11. Patrick
    Patrick avatar
    3 posts
    Member since:
    Mar 2014

    Posted 25 Mar 2014 in reply to Stefan Link to this post

    Hi! Sorry, but I'm not able to download the RadPropertyGridCustomItemElementCS.zip file. Do you know if the file is still there? Is there another way to have it? (perhaps the firewall at work block somthing). Because I think the code there should help me with what I have to test to replace some old grid with your GridView. Thank you very much, and have a nice day!

    -Patrick.
  12. Patrick
    Patrick avatar
    3 posts
    Member since:
    Mar 2014

    Posted 25 Mar 2014 in reply to Patrick Link to this post

    Sorry, finally got the file... we have a very poor network at work. Sorry for the inconvenients.
    Have a nice day!
    -Patrick.
  13. Carsten
    Carsten avatar
    4 posts
    Member since:
    Jun 2008

    Posted 29 Jan Link to this post

    Hi Stefan,

    Thank you. Your example helped us solve the problem. The buttons no longer disappear when scolling.

    I have another question. Is it possible to have the button, but still be able to edit the data, as if it was a standard textbox. We would like to have both options. I have tried to illustrate on the attached screendumb.

    Thanks 

    Carsten

  14. Carsten
    Carsten avatar
    4 posts
    Member since:
    Jun 2008

    Posted 29 Jan in reply to Carsten Link to this post

    Hi again

    Unfortunately we still have an issue when scrolling the property grid. The buttons are displayed, but CreateItemElement is not fired, when scrolling. We use CreateItemElement to set the item.Tag. We need the tag-value when the button is clicked.

    If you wish, I can send a modified version of RadPropertyGridCustomItemElement to show the problem.

    Regards, 

    Carsten

  15. Dess
    Admin
    Dess avatar
    1607 posts

    Posted 01 Feb Link to this post

    Hello Carsten,

    Thank you for writing.

    In order to allow editing the custom item element, you should cancel the edit operation only when you click over the button but activate the editor when clicking the text part. I have modified the sample project in order to achieve it. Note that in the EditorRequired event you can specify what editor type to be used. If you need to display the button in edit mode as well, feel free to use PropertyGridBrowseEditor. Note that you can create a custom PropertyGridBrowseEditor and perform your custom logic when pressing the browse button.

    As to the scrolling problem, I am not sure that it is reproducible in the sample project. Please refer to the attached zip file. Could you please specify the exact steps how to reproduce the problem?

    I am looking forward to your reply.

    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  16. Carsten
    Carsten avatar
    4 posts
    Member since:
    Jun 2008

    Posted 02 Feb in reply to Dess Link to this post

    Hello Dess,

     Thank you for your answer.I am now able to edit the textbox even if I have a custom item. 

     To reproduce the scrolling problem, you need to do the following:

    1. Add the CustomPropertyGridItemElement to SpecialText14 (the textbox at the bottom).

    2. Change the height of Form1 to 200.

    3. Add the following line to radPropertyGrid1_CreateItemElement:
    System.Diagnostics.Debug.Print(e.Item.Name);

    When you run the program and scroll to the bottom, you will notice, that radPropertyGrid1_CreateItemElement is not run for SpecialText14. We need to set a tag-value here.

    Regards,

    Carsten

  17. Dess
    Admin
    Dess avatar
    1607 posts

    Posted 03 Feb Link to this post

    Hello Carsten,

    Thank you for writing back. 

    Following the provided information I have updated the sample project in order to apply the custom item element to the SpecialText14 item. I am still unable to replicate any scrolling behavior. In addition, I can successfully update the textbox. Please refer to the attached gif file illustrating the behavior on my end. Am I missing something? I have attached the sample project. Could you please specify what changes I should perform in order to reproduce the undesired behavior? Thank you in advance.

    I am looking forward to your reply.

    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  18. Carsten
    Carsten avatar
    4 posts
    Member since:
    Jun 2008

    Posted 04 Feb in reply to Dess Link to this post

    Hello Dess,

     I'm sorry to be unclear. You need to make the following changes:

    1. Both SpecialText and SpecialText14 should have the custom editor.

    2. Try inserting a messagebox in radPropertyGrid1_CreateItemElement:

            private void radPropertyGrid1_CreateItemElement(object sender, CreatePropertyGridItemElementEventArgs e)
            {
                if (e.Item.Name == "SpecialText" || e.Item.Name == "SpecialText14")
                {
                    System.Windows.Forms.MessageBox.Show(e.Item.Name);
                    e.ItemElementType = typeof(CustomPropertyGridItemElement);
                }
                else
                {
                    e.ItemElementType = typeof(StandardItem);
                }
            }

    You will see, that you get the message for SpecialText. But when you scoll down you don't get the message for SpecialText14 (well a few times you actually do?!?).

    The custom editor for both SpecialText and SpecialText14 works, but I need to enter radPropertyGrid1_CreateItemElement in order to set a tag-value for the item (e.Item.Tag).

    Regards,

    Carsten

  19. Dess
    Admin
    Dess avatar
    1607 posts

    Posted 04 Feb Link to this post

    Hello Carsten,

    Thank you for writing back. 

    Note that RadPropertyGrid reuses its visual elements when scrolling. Elements reuse can be controlled in the PropertyGridItemElement.IsCompatible method. Thus, the first CustomPropertyGridItemElement is created for the "SpecialText" item. Afterwards, when you scroll down, the IsCompatible method will be triggered for different PropertyGridItems and for item "SpecialText14" it will be reused as the returned result is true. That is why the RadPropertyGrid.CreateItemElement event is not triggered for this item.

    I hope this information helps. If you have any additional questions, please let me know.

    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  20. Kenneth
    Kenneth avatar
    4 posts
    Member since:
    Oct 2016

    Posted 18 Oct in reply to Dess Link to this post

    Hello, I'm sorry for "necro-bumping" this thread, but I'm trying to do what you suggest here and It's not working for me.

    I'm using Progress OpenEdge and not C#. Apparently, I can't subclass your .net objects and then refer to them in the EditorRequired event.

    Long story short, I can't get a System.Type for an ABL object, so setting EditorType is something that I can't do.

    What I want to do is have a custom Dialog appear when clicking the "..." button instead of the Open File Dialog.

    I have subscribed to the BrowseButton's Click event, but unfortunately, the Open File Dialog pops up and my event doesn't fire until the box is closed.

     

    in EditorInitialized()

     
    DEF VAR vEditor AS IValueEditor NO-UNDO.
    DEF VAR vtmp AS RadBrowseEditorElement NO-UNDO.
     
    vEditor  = CAST(e:EDITOR             , "PropertyGridBrowseEditor").
    vtmp = CAST(vEditor:EditorElement, "RadBrowseEditorElement" ).
     
    vTmp:BrowseButton:Click:Subscribe(field_Click) NO-ERROR.

     

    METHOD PRIVATE VOID field_Click (sender AS CLASS System.Object, e AS CLASS System.EventArgs):
       MESSAGE "YAY" VIEW-AS ALERT-BOX.      
    END METHOD.

     

    I need to either override what happens when the button is clicked completely or cancel the dialog opening.

  21. Dess
    Admin
    Dess avatar
    1607 posts

    Posted 20 Oct Link to this post

    Hello Kenneth,

    Thank you for writing.  

    In the EditorRequired event, you can set either the PropertyGridEditorRequiredEventArgs.EditorType or the PropertyGridEditorRequiredEventArgs.Editor to replace the editor with the custom one:
    private void radPropertyGrid1_EditorRequired(object sender, PropertyGridEditorRequiredEventArgs e)
    {
        if (e.Item.Name == "SpecialText14" || e.Item.Name == "SpecialText")
        {
            e.Editor = new CustomPropertyGridBrowseEditor();
        }
    }

    I suppose that the code snippet above is doable in ABL.
     
    Should you have further questions I would be glad to help.

    Regards,
    Dess
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Back to Top
UI for WinForms is Visual Studio 2017 Ready