Set an "Appearance" property for a Infragistics co

Posted by agent_008_nl on 19-Jun-2009 04:54

Hi,

I'm trying to set the TextVAlign property of an ultralabel control using reflection. This property appears in the OEA propertygrid under the header "Appearance", you can set it statically with f.e.:

THIS-OBJECT:ultraLabel5:Appearance:TextVAlignAsString = "Top"

When I try to set it using reflection with f.e.

SetChildControlProperty (oControl, /* a valid ultralabelobject class System.Windows.Forms.Control */
                              'TextVAlignAsString',
                              BOX(Attrib.AttribValue))

it fails because of the invalid propertyname. Is it possible to get this working?

/*------------------------------------------------------------------------------
   Purpose:                    
   Notes:     made by  Mike Fechner             
------------------------------------------------------------------------------*/
METHOD PRIVATE VOID SetChildControlProperty (poControl AS System.Windows.Forms.Control,
                                              pcPropertyName AS CHARACTER,
                                              poPropertyValue AS System.Object):
 
        DEFINE VARIABLE oType     AS System.Type                    NO-UNDO .
        DEFINE VARIABLE oProperty AS System.Reflection.PropertyInfo NO-UNDO .

  IF NOT VALID-OBJECT (poControl) THEN
      UNDO, THROW NEW AppError ("No valid control!", 0) .
     
  oType = poControl:GetType() .

        oProperty = oType:GetProperty (pcPropertyName) .
   
        IF VALID-OBJECT (oProperty) THEN
            oProperty:SetValue (poControl, poPropertyValue, ?).  
  ELSE
            UNDO, THROW NEW AppError ("Invalid Property Name " + pcPropertyName, 0) .
 
  RETURN.

END METHOD.

--
Kind regards,

Stefan Houtzager

Houtzager ICT consultancy & development

www.linkedin.com/in/stefanhoutzager

All Replies

Posted by Admin on 19-Jun-2009 05:14

Stefan, Appearance is not just a "nice header" for a group of Properties. It's one of Infragistics Types (classes) and also a name of a property of most Infragistics objects. So basically you need to create a new Appearance object (i guess Infragistics.Win.Appearance or something like that) and assign that to your UltraLabel.

TextValignAsString is a property of the Appearance object, not the Control.

Your best (and only friend) when doing dynamic coding with (.NET) objects is the class browser

Posted by agent_008_nl on 19-Jun-2009 09:11

Thanks Mike,

Your friend is hiding himself somewhere in OEA, so I looked in http://help.infragistics.com/Help/NetAdvantage/NET/2008.2/CLR2.0/html/Infragistics2.Win.v8.2~Infragistics.Win.Appearance_members.html

for a method to set the appearance dynamically. Statically you could set TextVAlignAsString with this code, that is clear from the code the visual designer

generates:

DEFINE VARIABLE oAppearance AS Infragistics.Win.Appearance NO-UNDO.
oAppearance = NEW Infragistics.Win.Appearance().     
oAppearance:TextVAlignAsString = "Middle".

poControl:Appearance = oAppearance.

Allas I can find no suitable method in the Appearanceclass to set TextVAlignAsString dynamically.

Schönes Wochenende,

Stefan.

Posted by Admin on 19-Jun-2009 09:21

agent_008_nl schrieb:

Allas I can find no suitable method in the Appearanceclass to set TextVAlignAsString dynamically.

Schönes Wochenende,

Stefan.

Probably because there is no such method.

You need to modify the dynamic-property set from the Reflection example to work on any class, not just Controls; also I suggest to TextVAlign property, not the TextValignAsString property. My Reflection sample does show how to convert a character value to an enum value.

Enjoy the weekend.

Mike

Posted by agent_008_nl on 22-Jun-2009 07:15

Thanks again Mike,

I have something working now. If I have worked out a neat procedure I'll post it.

Servus,

Stefan.

This thread is closed