Adding custom editor for PropertyGridParameter in code-behind doesn't work.

  1. #1

    Adding custom editor for PropertyGridParameter in code-behind doesn't work.

    Please note I'm not trying to create anything dynamically in an AjaxEvent - this is just in Page_Load.

    protected void Page_Load(object sender, EventArgs e)
    {
        ImageLayer imageLayer = new ImageLayer();
    
        PropertyGridParameterCollection propertyGridParameters = new PropertyGridParameterCollection();
        foreach (PropertyDescriptor propertyDescriptor in TypeDescriptor.GetProperties(imageLayer))
        {
            object value = propertyDescriptor.GetValue(imageLayer);
    
            PropertyGridParameter propertyGridParameter = new PropertyGridParameter(propertyDescriptor.DisplayName, (value != null) ? value.ToString() : "[Null]");
            if (propertyDescriptor.PropertyType.IsEnum)
            {
                ComboBox comboBox = new ComboBox { EmptyText = "Please select..." };
                foreach (string enumValue in (Enum.GetNames(propertyDescriptor.PropertyType)))
                    comboBox.Items.Add(new ListItem(enumValue, enumValue));
                propertyGridParameter.Editor.Add(comboBox);
            }
            propertyGridParameters.Add(propertyGridParameter);
        }
        prgProperties.SetSource(propertyGridParameters);
    }
    I'm using the latest version, v0.8.1.2802. I can create the same PropertyGridParameter in markup, no problem, but not in code-behind. Is this a known issue?

    Thanks,
    Tim
  2. #2

    RE: Adding custom editor for PropertyGridParameter in code-behind doesn't work.

    Sorry, forgot to say, the only thing that doesn't work is - the custom editor (ComboBox) doesn't appear in the property grid. All the properties just appear with the default textbox editors. And yes, I've stepped into the code and it definitely is creating and attaching the combo boxes.
  3. #3

    RE: Adding custom editor for PropertyGridParameter in code-behind doesn't work.

    Yep,

    Have the same issue, blocking the use of coolite in my company.

    Too bad.

    i've tried to rebind, page load, ajax event, dolayout, everything possible, it is simply not working.

    However the object is created, items are in place, editor is bound to parameter.

    Interested if someone find a solution.

    Regards.
  4. #4

    RE: Adding custom editor for PropertyGridParameter in code-behind doesn't work.

    I built the following example and it appears to work correctly with the ComboBox Editor.

    Example

    <%@ Page Language="C#" %>
    
    <%@ Import Namespace="System.ComponentModel" %>
    <%@ Import Namespace="ListItem=Coolite.Ext.Web.ListItem" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Bind(new Person
            {
                Name = "Frank",
                DOB = DateTime.Today.AddYears(-30),
                Membership = Membership.Professional
            });
        }
    
        public void Bind(Person person)
        {
            foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(person))
            {
                object value = property.GetValue(person);
    
                PropertyGridParameter param = new PropertyGridParameter(property.Name, value != null ? value.ToString() : "[Null]");
    
                if (property.PropertyType.IsEnum)
                {
                    ComboBox comboBox = new ComboBox { EmptyText = "Please select..." };
    
                    foreach (string val in (Enum.GetNames(property.PropertyType)))
                    {
                        comboBox.Items.Add(new ListItem(val, val));
                    }
    
                    param.Editor.Add(comboBox);
                }
    
                this.PropertyGrid1.Source.Add(param);
            }
        }
    
        public class Person
        {
            public string Name { get; set; }
            public DateTime DOB { get; set; }
            public Membership Membership { get; set; }
        }
    
        public enum Membership
        {
            Community,
            Professional,
            Administrator
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>PropertyGrid - Coolite Examples</title>
        <link href="../../../../resources/css/examples.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ScriptManager runat="server" />
                   
            <ext:PropertyGrid ID="PropertyGrid1" runat="server" Width="300" AutoHeight="true">
                <View>
                    <ext:GridView ForceFit="true" ScrollOffset="2" runat="server" />
                </View>
            </ext:PropertyGrid>
        </form>
    </body>
    </html>
    Hope this helps.

    Geoffrey McGill
    Founder

Similar Threads

  1. [CLOSED] visible in code behind doesn't work for portlet
    By CarpFisher in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 29, 2012, 12:30 PM
  2. Replies: 2
    Last Post: Mar 15, 2012, 12:57 AM
  3. Replies: 2
    Last Post: Oct 25, 2011, 11:10 AM
  4. Replies: 0
    Last Post: Jul 22, 2009, 2:05 PM
  5. Replies: 2
    Last Post: Nov 04, 2008, 12:28 AM

Posting Permissions