 |
|
 |
Hello, Your piece of code just saved my life! I have been trying for several days to make the PropertyGrid control work in LabView. LabView can interact with .NET objects and controls but does not have the ability to create a .NET object required to populate a PropertyGrid. Thanks to your new class, it's not a problem anymore. I will be able to display an arbitrary cluster of data (structure) in a PropertyGrid at runtime. I have not tried to change the attribute yet but it should work as well. Thanks again, good job
Pierre Cottin
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
Hi..
Your code has been a lot of use for me. Thanks a lot. I wanted to know how would u modify the code to have ur property grid sensitive to datatype. I mean, if one of the properties is datetime then i want the propertygrid to treat it as one and not string. I need the datepicker control to be invoked when i click it.
Hari
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I have tried to use this class in a asp.net propertygrid but it failed. It returns real properties instead of the created properties. Here is the reason,
there is 2 calling type for getproperties function, the one public PropertyDescriptorCollection GetProperties(Attribute[] attributes) works fine but the other which is used by the asp.net propertygrid public PropertyDescriptorCollection GetProperties() fails to return thr correct property descriptors.
So i have changed the code in the asp.net property grid to first function by calling with an empty attribute.
But rest works fine. Thank you
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
 | Type  Lions_italy | 22:28 16 Jan '06 |
|
|
 |
|
 |
Hi,
I have a property "Color" on my property grid.
public Color Color { get { return this.color; } set { this.color = value; } }
I would like to apply dynamically the [ReadOnly()] attribute on this property. Is it possible?
John J
|
| Sign In·View Thread·PermaLink | 3.86/5 |
|
|
|
 |
|
 |
If you're looking to 'undo' or apply a readonly attribute for an object during runtime shown on the propertygrid, you need to create your own propertydescriptor, derived from System.ComponentModel.PropertyDescriptor, and use the following code:
public CustomPropertyDescriptor(PropertyDescriptor propertyDescriptor, Attribute[] attribute) : base(propertyDescriptor, attribute) { this.propertyDescriptor = TypeDescriptor.CreateProperty( propertyDescriptor.ComponentType, propertyDescriptor, attribute); }
Furthermore, from the class implementing ICustomTypeDescriptor (I used System.ComponentModel.CustomTypeDescriptor), do the following in the GetProperties() method:
public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) { ArrayList newProperties = new ArrayList(); PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(component); CustomPropertyDescriptor customPropertyDescriptor; Attribute[] readOnlyAttribute = new Attribute[] { ReadOnlyAttribute.No }; Attribute[] browsableAttribute = new Attribute[] {BrowsableAttribute.No }; foreach (PropertyDescriptor propertyDescriptor in properties) { if (propertyDescriptor.GetValue(component) is IList) { customPropertyDescriptor = new CustomPropertyDescriptor(propertyDescriptor, browsableAttribute); } else { customPropertyDescriptor = new CustomPropertyDescriptor(propertyDescriptor, readOnlyAttribute); } newProperties.Add(customPropertyDescriptor); } return new PropertyDescriptorCollection((PropertyDescriptor[])newProperties.ToArray(typeof(PropertyDescriptor))); }
The above code will ignore the ReadOnly attribute by adding a ReadOnly.No attribute on the properties, and hide the properties that are IList based (collections)
|
| Sign In·View Thread·PermaLink | 2.25/5 |
|
|
|
 |
|
 |
See a good article Bending the .NET PropertyGrid to Your Will by Tony Allowatt her on this site
This explains a lot of your questions............
Signing Off.... ByteGhost
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi Sreejumon
I observed your reply to Damslang gives the answer also my question. Thanks for this. However I will be very greatful to you if you give me a help to solve this drawback. I have modified CustomProperty in order to handle also the type of the property. For example, in case of boolean data, I will have this code:
CustomProperty myProp = new CustomProperty(txtCategory.Text, txtHelp.text, typeof(bool), txtName.Text, txtValue.Text, chkReadOnly.Checked,true);
The case will be more complex if I want to select a property value from a combolist of data. I image that I should change CustomProperty in order to satisfy this condition:
CustomProperty myProp = new CustomProperty(txtCategory.Text, txtHelp.text, typeof(StatesList), txtName.Text, txtValue.Text, chkReadOnly.Checked,true);
where StatesList is a class, for example, so made:
public class StatesList : System.ComponentModel.StringConverter { string[] _States = {"Alabama", "Alaska", "Arizona", "Arkansas"}; public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { return new StandardValuesCollection(_States); } public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { return true; } public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) { return true; } } Can you tell me if I have choosen the right way ?. Otherwise can you suggest me the correct approch ? Thanks. Best regards
Poletto
|
| Sign In·View Thread·PermaLink | 3.00/5 |
|
|
|
 |
|
|
 |
|
 |
Great work! I m writing a config file editor and this was a great way to dynamically read the xml properties and add them to the propertygrid. Just one question : how could one add description and category attributes to each property?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
;PDon't worry i've figured it out on my own, quite simple : Added two properties Description and Category in CustomProperty and then in CustomPropertyDescriptor i return m_Property.Description and m_Property.Category
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
 |
Hi Sreejumon
I have visited your sample about dynamic property grid. I am trying to use it in my application, but I find it not completed. For example I need to decide the category where collecting the property and its help-description. Can you give me a help to modify your code ?. Best regards
Maurizio
|
| Sign In·View Thread·PermaLink | 4.22/5 |
|
|
|
 |
|
 |
Hi Sreejumon,
I tried this code sample to create property grid items dynamicall and it works fine.
The problem is I am nor longer use EditorAttribute feature of UiTyeEditor .So all my check Boxes and dropdown lists created in property grid is ignored if I use ICustomTypeDescriptor in my class. Can you help me how to use editorattribute feature in Cuatom property creation ? I am new to c# and propertygrid.
Cheers, Rajan
Rajan
|
| Sign In·View Thread·PermaLink | 2.14/5 |
|
|
|
 |