I'm using Progress OpenEdge 11.6 and I'm implementing a RadPropertyGrid that contains a property of type System.Drawing.Font.
When The Font property is displayed it automatically includes an expandable section which I want to keep, but some of the options are irrelavent to this app and I want to hide or remove them.
After reviewing the documentation and the other forum threads here, I tried the following code:
/*------------------------------------------------------------------------------
Purpose:
Notes:
------------------------------------------------------------------------------*/
@VisualDesigner.
METHOD PRIVATE VOID Props_CreateItemElement( INPUT sender AS System.Object,
INPUT e AS CreatePropertyGridItemElementEventArgs ):
IF e:ITEM:parent <> ? AND
e:ITEM:parent:Label =
"Font"
THEN
IF e:ITEM:Label =
"Unit"
OR
e:ITEM:Label =
"GdiCharSet"
OR
e:ITEM:Label =
"GdiVerticalFont"
THEN
e:ITEM:Visible = NO.
RETURN.
END METHOD.
This appears to work initially when I expand the Font Property, these three items are not there, but as soon as I change one of the properties (such as changing the Bold flag) the hidden items reappear.
Am I not using the appropriate event to do this? Did I miss an event?
Please help.
8 Answers, 1 is accepted
Thank you for writing.
In order to hide some of the subitems in RadPropertyGrid, it is necessary to iterate the relevant PropertyGridItem.GridItems collection and set the Visible property to false for the certain item:
public
RadForm1()
{
InitializeComponent();
this
.radPropertyGrid1.SelectedObject =
this
;
foreach
(PropertyGridItem item
in
this
.radPropertyGrid1.Items)
{
if
(item.Label ==
"Font"
)
{
foreach
(PropertyGridItem subItem
in
item.GridItems)
{
if
(subItem.Label ==
"Unit"
||
subItem.Label ==
"GdiCharSet"
||
subItem.Label ==
"GdiVerticalFont"
)
{
subItem.Visible =
false
;
}
}
break
;
}
}
}
I hope this information helps. Should you have further questions I would be glad to help.
Regards,
Dess
Telerik by Progress

I tried this as you suggested. Here's the OpenEdge equivalent of your suggestion:
props:SelectedObjects = propArray.
{
foreach
.i PropertyGridItem vItem
in
props:Items }
IF vItem:LABEL =
"Font"
THEN
DO:
{
foreach
.i PropertyGridItem vSubItem
in
vItem:GridItems }
IF vSubItem:LABEL =
"Unit"
OR vSubItem:LABEL =
"GdiCharSet"
OR vSubItem:LABEL =
"GdiVerticalFont"
THEN vSubItem:VISIBLE = FALSE.
END.
LEAVE.
END.
END.
the foreach.i is a macro that emulates the behavior of a C# foreach statement (since OpenEdge doesn't have a similar construct).
Anyway, I still have the same problem.
If you expand the Font item, the subitems are gone, but as soon as you change one of the properties, they reappear. Please see the attached images.

I'd also like to add that what I think is happening is that the property text of the Font line itself is changing (from "Arial, 10pt" to "Arial, 10pt, style=Bold") and that is triggering a reload of the System.Drawing.Font's subitems.
I believe this is the case because if I click off of my <TEXT> object (seen in the screenshots) and then back onto it, the Font property's subitems are hidden again.

I was able to make it work by adding the following to the PropertyValueChanged event:
METHOD PRIVATE VOID Props_PropertyValueChanged(INPUT sender AS System.Object,
INPUT e AS PropertyGridItemValueChangedEventArgs ):
DEF VAR pgiTmp AS PropertyGridItem NO-UNDO.
pgiTmp = CAST(e:ITEM, PropertyGridItem).
IF pgiTmp:LABEL =
"Font"
THEN
DO:
{
foreach
.i PropertyGridItem vSubItem
in
pgiTmp:GridItems }
IF vSubItem:LABEL =
"Unit"
OR vSubItem:LABEL =
"GdiCharSet"
OR vSubItem:LABEL =
"GdiVerticalFont"
THEN vSubItem:VISIBLE = FALSE.
END.
END.
END METHOD.
Now this works, but it feels like a hack. I'd still like to know if there's a cleaner way of doing this.
Thank you for writing back.
Indeed, when you change the Font property, the hidden items show again. As you have already found out, the suitable approach is to handle the PropertyValueChanged event and hide the undesired PropertyGridItems.
private
void
radPropertyGrid1_PropertyValueChanged(
object
sender, PropertyGridItemValueChangedEventArgs e)
{
foreach
(PropertyGridItem item
in
this
.radPropertyGrid1.Items)
{
if
(item.Label ==
"Font"
)
{
foreach
(PropertyGridItem subItem
in
item.GridItems)
{
if
(subItem.Label ==
"Unit"
||
subItem.Label ==
"GdiCharSet"
||
subItem.Label ==
"GdiVerticalFont"
)
{
subItem.Visible =
false
;
}
}
break
;
}
}
}
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Telerik by Progress

I am in the same scenario, but the object that is in question is an Enum. Given the exact same scenario, the subItems.GridItems is 0, when you indeed see all the enum values in the drop down. Does this not work the same for Enums?
what I would like to do is disable or remove one of the property values that is not allowed in certain situations, but so far I am not seeing this as an option.
I am attached a snippet of my test code so you can replicate.
namespace
TestingTelerikPropertyGrid
{
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
var temp =
new
TestingClass();
propertyGrid.SelectedObject = temp;
foreach
(var item
in
propertyGrid.Items)
{
if
(item.Label !=
"StereoMode"
)
{
continue
;
}
foreach
(var subItems
in
item.GridItems)
{
if
(subItems.Name ==
"Interleaved"
)
{
subItems.Visible =
false
;
}
}
}
}
}
public
enum
MyTestEnum { Off, PassiveLeft, PassiveRight, ActiveLeft, ActiveRight, Interleaved }
public
class
TestingClass
{
public
TestingClass()
{
StereoMode = MyTestEnum.Off;
MyNumber = 123;
}
public
MyTestEnum StereoMode {
get
;
set
; }
public
int
MyNumber {
get
;
set
; }
}
}
Thank you for writing back.
If I understand your requirement correctly, you are trying to hide just one option from the enum values when editing the specific item. For this case, it is necessary to subscribe to the EditorInitialized event and remove the redundant items. Here is a sample code snippet:
private
void
RadPropertyGrid1_EditorInitialized(
object
sender, PropertyGridItemEditorInitializedEventArgs e)
{
PropertyGridDropDownListEditor editor = e.Editor
as
PropertyGridDropDownListEditor;
if
(editor !=
null
)
{
BaseDropDownListEditorElement el = editor.EditorElement
as
BaseDropDownListEditorElement;
int
index = -1;
foreach
(RadListDataItem item
in
el.Items)
{
if
(item.Text ==
"ActiveRight"
)
{
index = el.Items.IndexOf(item);
break
;
}
}
if
(index > -1)
{
el.Items.RemoveAt(index);
}
}
}
If it is not the exact requirement it would be greatly appreciated if you can specify in details what is the exact requirement that you are trying to achieve. Thus, we would be able to assist you further. Thank you.
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Telerik by Progress
