Adding a lookup button to a RadPropertyGrid item

Posted by Evy De Block on 01-Feb-2016 04:19

Has anyone an idea how to achieve this with OpenEdge code?
I have found some C# and VB samples but those samples are using properties I can't find in 'my world'.

All Replies

Posted by gdb390 on 02-Feb-2016 02:27

Probably because you need to add some extra assembly references.

Which properties are you looking for ?

Posted by Evy De Block on 02-Feb-2016 02:35

I have to create a new RadButton (this part is ok of course) and add this button as a child element to a valueItem of the propertyGrid.  The button has to be visible all the time, so not only when the value is edited.

I need something like this: Me.ValueElement.Children.Add(myButton).

Posted by gdb390 on 02-Feb-2016 04:20

Take a look at www.telerik.com/.../propertygrid-custom-items.html

Instead of the radiobuttonelement, use the RadButtonElement (do not use RadButton)

Posted by Evy De Block on 03-Feb-2016 04:54

I think I expressed myself in the wrong way ...

What I want to do is write a custom editor class (in my case a custom PropertyGridButtonEditor) and use this custom editor in the _editorRequired event of my propertyGrid.  Something like:

e:EditorType = Progress.Util.TypeHelper:GetType("PropertyGridButtonEditor").

I still get errors on this statement because I assume there is something wrong in my PropertyGridButtonEditor class.

Posted by gdb390 on 03-Feb-2016 07:41

Two possible causes :

1. Is your PropertyGridButtonEditor a class in the root directory ?  If not -> are you using a using statement ?

   I personally don't like using statement and always use the fully referenced class name (package + class)

2. are the EditorType and the result of the GetType of the same type ? Maybe you need an extra cast

In my project this works fine :

Custom Editor :

----------------------

using Progress.Lang.*.

using Telerik.WinControls.UI.BaseInputEditor.

block-level on error undo, throw.

class RadPropertyGrid.PropertyGridButtonEditor inherits BaseInputEditor:

define override public property DataType as System.Type

get.

method override protected Telerik.WinControls.RadElement CreateEditorElement(  ):

undo, throw new Progress.Lang.AppError("METHOD NOT IMPLEMENTED").

end method.

end class.

In form where radpropertygrid is used :

@VisualDesigner.

method private void radPropertyGrid1_EditorRequired( input sender as System.Object, input e as Telerik.WinControls.UI.PropertyGridEditorRequiredEventArgs ):

e:EditorType = Progress.Util.TypeHelper:GetType("RadPropertyGrid.PropertyGridButtonEditor").

return.

end method.

Posted by Evy De Block on 03-Feb-2016 08:08

I completely agree that using the fully referenced class name makes code more readable so I avoid the 'using' statement in my code.

I have compared your code with the code I am using and we are doing exactly the same!

It looks like the editorRequired statement executes fine, but afterwards an error is shown:

System.ArgumentNullException: value cannot be null.

Am I missing something in the form where I use the radPropertyGrid?

Can you do me a favour and attach a screenshot of your application where u use this custom editor?

I would like to see the final result.

Posted by Laura Stern on 03-Feb-2016 08:27

Sorry, but I'm missing the whole thing.  

1. I don't understand this event and why you need to fill in the Type in the args object.  But I guess that is my problem!  The doc doesn't seem to explain it.

2. You are trying to get the System.Type of the current class (THIS-OBJECT), right?.  Why don't you just call THIS-OBJECT:GetType().  You shouldn't need the Helper.

Posted by gdb390 on 03-Feb-2016 08:30

It is not the type of the current class but the type of the custom editor where you want eg. to replace the integer field with a slider

Posted by gdb390 on 03-Feb-2016 08:37

I didn't try to run it :)

I got no compile error, and I thought that's what you were getting

If I run it, I do get a runtime error, the same a you from the moment I click on it

Posted by Evy De Block on 03-Feb-2016 08:44

Hmmm ... it looks like we are getting the same result: nothing :-)

Are you using OE11.5 or 11.6?

I am still on OE11.5 on the environment where I am testing it, so I hoped a little bit that you didn't have the problem because you were on OE11.6

I think I will log another call with tech support :-)

Posted by gdb390 on 03-Feb-2016 08:48

11.6 64 bit and Telerik version 2016.Q1

Posted by Evy De Block on 03-Feb-2016 08:52

And still the same result: not good :-)

Posted by Laura Stern on 03-Feb-2016 08:59

Re: It is not the type of the current class but the type of the custom editor where you want eg. to replace the integer field with a slider:

OK.  That makes sense as a concept.  But I thought this IS the customer editor class.  And if it's not this class, why am I seeing that the name in the GetType call is  RadPropertyGrid.PropertyGridButtonEditor which is the same as the name of the ABL class that I'm in:  RadPropertyGrid.PropertyGridButtonEditor.  

If PropertyGridButtonEditor is an ABL class, not a .NET class, you can't get a Type for an ABL class via the Helper.  Though GetType() on the instance will give you something, since that will call GetType() on the .NET proxy for your ABL class.  

Posted by Evy De Block on 03-Feb-2016 09:21

Laura, is it possible to write a simple sample that uses a custom editor class?

Posted by gdb390 on 03-Feb-2016 09:40

Laura,  in the code above there is the class RadPropertyGrid.PropertyGridButtonEditor

The bottom part of the code is the method of the EditorRequired from the form (or in my case an ABL user control)

What should be used then instead of code below ?

e:EditorType = Progress.Util.TypeHelper:GetType("RadPropertyGrid.PropertyGridButtonEditor")

Posted by Laura Stern on 03-Feb-2016 09:44

Sorry - I've never used these controls and don't know how to use them - which should be obvious by my previous answers!  

Posted by gdb390 on 03-Feb-2016 09:46

In the code there are 2 pieces ...

one with the class

using Progress.Lang.*.

using Telerik.WinControls.UI.BaseInputEditor.

block-level on error undo, throw.

class RadPropertyGrid.PropertyGridButtonEditor inherits BaseInputEditor:

define override public property DataType as System.Type

get.

method override protected Telerik.WinControls.RadElement CreateEditorElement(  ):

undo, throw new Progress.Lang.AppError("METHOD NOT IMPLEMENTED").

end method.

end class.

and the other is the method in the form : 

@VisualDesigner.

method private void radPropertyGrid1_EditorRequired( input sender as System.Object, input e as Telerik.WinControls.UI.PropertyGridEditorRequiredEventArgs ):

e:EditorType = Progress.Util.TypeHelper:GetType("RadPropertyGrid.PropertyGridButtonEditor").

return.

end method.


The question remains : how must the type be returned in EditorRequire method ?

Posted by Laura Stern on 03-Feb-2016 09:47

I think I've already explained about using THIS-OBJECT:GetType(), but that presumes that that is what you want to do.  And I'm not at all sure it is based on the comment by gdb390.  You need to explain to me in English what you are trying to do by this line - at a high level.  What object are you trying to get the Type of?

Posted by gdb390 on 03-Feb-2016 09:47

Laura, no problem, you can't know it all ;)

Evy, are you going to log it with TS , please keep me informed

Posted by Laura Stern on 03-Feb-2016 09:51

No one addressed my previous post - is the object you are trying to get the Type of the custom class written in the ABL?  If it is, then you need to do what I said. It wouldn't be THIS-OBJECT:GetType() as now you've explained that that code is the form, not the custom class itself.  But you must have an instance of the custom class (RadPropertyGrid.PropertyGridButtonEditor).  Call GetType() on that instance.  As I explained, you can only use the Helper on pure .NET classes -  not on an ABL class that inherits from .NET.

Posted by gdb390 on 03-Feb-2016 10:07

yes, we need the type of the custom class written in ABL

I'll try some things out this week

Posted by Evy De Block on 04-Feb-2016 03:02

Hi Laura,

I think I understand what you mean and I tried it on the sample gdb provided.

I do something like this in the radPropertyGrid1_EditorRequired method:

define private variable mybuttonEditor as RadPropertyGrid.PropertyGridButtonEditor no-undo.

mybuttonEditor  = new RadPropertyGrid.PropertyGridButtonEditor().

e:EditorType = buttonEditor:getType().

This code compiles but if I run it I get another error:

System.InvalidOperationException: calling method

CreateEditorElement

Followed by:

A .Net object is attempting to access a method or property of an ABL/.net hybrid class that already been deleted.

Any idea on this?

Posted by Laura Stern on 04-Feb-2016 08:33

It would help if you turned on debugalert (either -debugalert or session:debug-alert = yes) and look at the stack trace you get when this error comes up.  

I'm not sure if it has anything to do with the fact that your CreateEditorElement method is throwing an error.  I wouldn't think this would cause that particular error (14791).  But even if not, I would suspect that this will not work very well overall.  I don't understand the point of having a custom version of this class that doesn't do anything - actually worse - it takes functionality away by basically disabling this method.  But as I already said - I don't know how this class works, so if you know better, please let me know!

Posted by Evy De Block on 04-Feb-2016 08:47

At the end the PropertyGridButtonEditor class will contain code to create a button.  This button will appear in the ItemValueField of the propertyGrid at the moment the user clicks the item field and the field goes in edit mode.

At the moment we removed all the extra code from our class because we want to find out what is causing the error first.
Here is the stack trace:

Unfortunatly the Telerik propertyGrid has nothing build-in to add a button to a valueField, so we have to write our own class to make it possible.  

Please see the Telerik documentation about this topic:
http://www.telerik.com/help/winforms/propertygrid-editors-using-custom-editor.html

If you know a better way to achieve the result we wanted, I am happy to hear it because we are stuck at the moment.

Posted by Laura Stern on 04-Feb-2016 10:33

An instance of your custom class needs to exist at the time that the grid is displayed.  And somehow the grid needs access to that instance.  How is that happening?  I presume you set it somewhere.  But this error is simply saying that at the time the grid is trying to call the CreateEditorElement method there is no longer a valid instance of the class in the ABL to call.  Remember that the ABL does garbage collection so if the class instance was created in a context that has gone out of scope, we will have garbage collected it.

This thread is closed