Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I've added a new property to my custom control as expandable property like font property in Property Grid. After using from my custom control in a Windows Forms Application project, I see an ellipsis (…) button like "…" button of font property in Property Grid. (For more information, please see the following picture.)
One of my custom control properties[^]
Now, I want to hide the ellipsis (…) button for my new expandable property.
Expandable property codes are:
C#
[DisplayName("Floors Information")]
[Description("Floors Informationnnnnnnnnnnnnnnn")]
[DefaultProperty("TitleText")]
[DesignerCategory("Component")]
public class FloorsInformation : DockContainerItem
{
    private SimilarFloorsInformation similarFloorsInformation = new SimilarFloorsInformation();

    public FloorsInformation()
    {

    }

    [Category("Data")]
    [DisplayName("Similar Floors Panel")]
    [Description("Similar Floors Panellllllllllllllllllll")]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    [Editor(typeof(ItemsCollectionEditor), typeof(UITypeEditor))]
    //[TypeConverter(typeof(ExpandableObjectConverter))]
    //[TypeConverter(typeof(SimilarFloorsInformationTypeConverter))]
    public SimilarFloorsInformation SimilarFloorsInfo
    {
        get
        {
            return similarFloorsInformation;
        }
    }
}

[DisplayName("Similar Floors Information")]
[Description("Similar Floors Informationnnnnnnnnnnnnnnn")]
[DefaultProperty("Text")]
[DesignerCategory("Component")]
[TypeConverter(typeof(SimilarFloorsInformationTypeConverter))]
//[TypeConverter(typeof(ExpandableObjectConverter))]
public class SimilarFloorsInformation : ExpandablePanel
{
    private Color canvasColor = SystemColors.Control;
    private eCollapseDirection collapseDirection = eCollapseDirection.LeftToRight;
    private eDotNetBarStyle colorSchemeStyle = eDotNetBarStyle.StyleManagerControlled;
    private DockStyle dock = DockStyle.Right;
    private eTitleButtonAlignment expandButtonAlignment = eTitleButtonAlignment.Left;
    private bool expanded = false;
    private bool markupUsesStyleAlignment = true;
    private Size size = new Size(30, 177);

    public SimilarFloorsInformation()
    {

    }
}

public class SimilarFloorsInformationTypeConverter : ExpandableObjectConverter//TypeConverter
{
    public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
    {
        if (destinationType == typeof(SimilarFloorsInformation))
        {
            return true;
        }
        return base.CanConvertTo(context, destinationType);
    }

    public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
    {
        if (destinationType == typeof(String) && value is SimilarFloorsInformation)
        {
            SimilarFloorsInformation similarFloorsInformation = (SimilarFloorsInformation)value;
            return similarFloorsInformation.TitleText;
        }
        return base.ConvertTo(context, culture, value, destinationType);
    }

    public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
    {
        if (sourceType == typeof(string))
        {
            return true;
        }
        return base.CanConvertFrom(context, sourceType);
    }

    public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
    {
        if (value is string)
        {
            SimilarFloorsInformation similarFloorsInformation = new SimilarFloorsInformation();
            similarFloorsInformation.TitleText = (string)value;
            return similarFloorsInformation;
        }
        return base.ConvertFrom(context, culture, value);
    }
}
Posted
Updated 10-Oct-12 20:39pm
v2

This is not how property grid works and customized. You don't show or hide the grid features, you change the data model. The idea is: you assign SelectedObject property of the PropertyGrid, and it presents your object. How to customize it: you use some different object, which only represents your target object indirectly, through implementing of the interface System.ComponentModel.ICustomTypeDescriptor. This way, you can disable showing the custom editor for font object already available in the .NET Framework Class Library (FCL), and present the font in some different way: for example, you can show a font as a child node of the grid tree, and show its properties as separate sub-nodes.

This technique is described in more detain in my past answer:
How to get response when click PropertyGrid[^].

—SA
 
Share this answer
 
Comments
MRS1989 11-Oct-12 1:07am    
Tnx Sergey Alexandrovich Kryukov. I will check it.
MRS1989 11-Oct-12 2:05am    
Sergey Alexandrovich Kryukov, I couldn't implement ICustomTypeDescriptor for achieve to my goal. Can you guide me more?
Sergey Alexandrovich Kryukov 11-Oct-12 3:33am    
Look, couple of members asked me already, but it would be a matter of a really big article. I have a couple more in my queue. I do have code, but it should be re-worked before I can start the article. At the same time, I found out how to do it all from Microsoft documentation and nothing else, so you should be able to do the same. If I ever find time for that articles, I gladly do it.
--SA
MRS1989 11-Oct-12 3:34am    
Tnx Sergey Alexandrovich Kryukov for ur reply.
I solved my problem. Ellipsis (...) button is shown for following line of code (Attribute) that I've applied to the "SimilarFloorsInfo" property of my custom control:
C#
[Editor(typeof(ItemsCollectionEditor), typeof(UITypeEditor))]

So, this line of code must be deleted or commented. Now, Ellipsis (...) button not shown for my property in the property grid.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900