Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Hiding property value in property grid.
 

Hiding property value in property grid.

Hi folks.
I have a performance problem with some of my properties in my custom workflow designer.
The property in question is of type String, and holds rich text data. If there is much data stored in the property, the designer uses a long time to preview the contents of the property.

I'm looking for a way to either hide the value of this property in the property grid, or to optimize the preview.
I have not found any property attributes to hide the value of a property.

Does anyone have suggestions?
gix1
gix1  Monday, May 18, 2009 12:08 PM
Hi gix1,

If you don't like the property to be edited, you can hide the property by the Browsable attribute.

[Browsable(false)]
public string P1
{
get { return p1; }
set { p1 = value; }
}

If you need the property to be displayed on the Properties Windows, but hide its value(show blank on the value box), you can use a custom TypeConverter, for example:

public class mycontrol : UserControl
{
private string p1 = "aaaaa";

//[Browsable(false)]
[TypeConverter(typeof(P1TypeConverter))]
public string P1
{
get { return p1; }
set { p1 = value; }
}
}

public class P1TypeConverter : TypeConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(string))
return true;
else
return false;
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
return true;
else
return false;
}

public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
return value.ToString();
}

public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
return "";
}
}

Please try my suggest and let me know if it helps.

Best Regards,
Zhi-Xin


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Send us any feedback you have about the help from MSFT at fbmsdn@microsoft.com.
  • Marked As Answer bygix1 Friday, May 22, 2009 7:59 AM
  •  
Zhi-Xin Ye  Wednesday, May 20, 2009 1:51 PM
Hi gix1,

If you don't like the property to be edited, you can hide the property by the Browsable attribute.

[Browsable(false)]
public string P1
{
get { return p1; }
set { p1 = value; }
}

If you need the property to be displayed on the Properties Windows, but hide its value(show blank on the value box), you can use a custom TypeConverter, for example:

public class mycontrol : UserControl
{
private string p1 = "aaaaa";

//[Browsable(false)]
[TypeConverter(typeof(P1TypeConverter))]
public string P1
{
get { return p1; }
set { p1 = value; }
}
}

public class P1TypeConverter : TypeConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(string))
return true;
else
return false;
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
return true;
else
return false;
}

public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
return value.ToString();
}

public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
return "";
}
}

Please try my suggest and let me know if it helps.

Best Regards,
Zhi-Xin


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Send us any feedback you have about the help from MSFT at fbmsdn@microsoft.com.
  • Marked As Answer bygix1 Friday, May 22, 2009 7:59 AM
  •  
Zhi-Xin Ye  Wednesday, May 20, 2009 1:51 PM
Zhi-Xin, that did the trick. Thank you!
gix1
gix1  Friday, May 22, 2009 7:59 AM

You can use google to search for other answers

Custom Search

More Threads

• Using existing UIEditors in a custom PropertyGrid
• How to manage menu items when a user login?
• Custom Form Designer. Load menu problems.
• Called Forms referencing calling Forms controls
• ComboBox Databinding
• Designer error
• Adding code to VS 2005 generated windows form.
• Custom control with data binding sample
• Data Adapater Layout In Component Doesn't Persist
• How to Show form in Quick lunch rather than Task bar