propertygrid

Property Grid Number formatting

荒凉一梦 提交于 2019-11-28 00:05:32
问题 Is it possible to format numerical properties displayed in PropertyGrid of winforms? class MyData { public int MyProp {get; set;} } And I want it to be displayed in the grid as 1.000.000 for example. Are there some attributes for this? 回答1: You should implement custom type converter for your integer property: class MyData { [TypeConverter(typeof(CustomNumberTypeConverter))] public int MyProp { get; set; } } PropertyGrid uses TypeConverter to convert your object type (integer in this case) to

How do I inject a custom UITypeEditor for all properties of a closed-source type?

折月煮酒 提交于 2019-11-27 23:54:11
I want to avoid placing an EditorAttribute on every instance of a certain type that I've written a custom UITypeEditor for. I can't place an EditorAttribute on the type because I can't modify the source. I have a reference to the only PropertyGrid instance that will be used. Can I tell a PropertyGrid instance (or all instances) to use a custom UITypeEditor whenever it encounters a specific type? Here is an MSDN article that provides are starting point on how to do this in .NET 2.0 or greater. You can usually associate editors etc at runtime via TypeDescriptor.AddAttributes . For example (the

How can I use a WinForms PropertyGrid to edit a list of strings?

柔情痞子 提交于 2019-11-27 20:35:08
In my application I have a property grid to allow users to change settings. This works fine for strings and other value properties, but what I need now is a list of strings that can be edited by users. The problem is that if I have MyPropertyGrid.SelectedObject = new { Test = new List<string>() }; in my code and the user attempts to edit the Test property, when they click on the Add button, the following error occurs: Constructor on type 'System.String' not found This makes sense as strings are immutable. However, I still need some way to store multiple strings (or string-like data) in a

How to modify PropertyGrid at runtime (add/remove property and dynamic types/enums)

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 19:04:48
How do you modify a propertygrid at runtime in every way? I want to be able to add and remove properties and add "dynamic types", what I mean with that is a type that result in a runtime generated dropdown in the propertygrid using a TypeConverter. I have actually been able to do both those things (add/remove properties and add dynamic type) but only separately not at the same time. To implement the support to add and remove properties at runtime I used this codeproject article and modified the code a bit to support different types (not just strings). private System.Windows.Forms.PropertyGrid

Make a property visible in DataGridView but NOT in PropertyGrid?

我只是一个虾纸丫 提交于 2019-11-27 18:36:04
问题 Let's say I have a property which I want shown in a DataGridView, but not when the same object is shown in a PropertyGrid. I know I can use [Browsable(false)] , but that hides it in both views. I can also do a gridView.Columns["blah"].Visible = false; , but this is the opposite of what I want, as it hides in the DataGridView but not in PropertyGrid. Is there some way to do the reverse? (Short of creating a whole new DataTable just to hold the same data minus one field, and rebinding

How do you create a custom collection editor form for use with the property grid?

风格不统一 提交于 2019-11-27 16:31:07
问题 I am trying to incorporate a property grid control with a class that has a list/collection of another class as one of the properties. Lets call them class A and the list would be containing class B for reference. I was wanting to incorporate a form that had two list boxes. The list box on the left would contain a list of all of class B's in my program that are not currently in the list on the right. The list on the right would contain all of the class B's that are currently associated with

Using a Dictionary in a propertygrid

十年热恋 提交于 2019-11-27 16:17:31
问题 I'd like to edit a list of key value(string, string) items using a propertygrid. When I use a Dictionary<string,string> as type the propertygrid will show a GUI, but it does not seem "enabled", ie. I can't add any items. Is the Dictionary object supported, or is there any other object with which I could solve this problem? 回答1: I have done it following this code in the past: class DictionaryPropertyGridAdapter : ICustomTypeDescriptor { IDictionary _dictionary; public

PropertyGrid Browsable not found for entity framework created property, how to find it?

一曲冷凌霜 提交于 2019-11-27 15:55:07
Trying to remove or place items on a property grid by changing the Browsable attribute. But unless browsable is set on object creation my code to change Browsable doesn't work. Now I can manually add browsable, but when I make a change to my entity (still developing project so lots of changes to entity) any additional attributes I add go away. I attempted to set [Browsable(true)] two ways other ways: http://ardalis.com/adding-attributes-to-generated-classes and http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/617ebfca-0f68-4b90-83fd-0da758fadbd0/ Both seem to

Multi-line string in a PropertyGrid

∥☆過路亽.° 提交于 2019-11-27 15:33:03
问题 Is there a built-in editor for a multi-line string in a PropertyGrid . 回答1: I found that System.Design.dll has System.ComponentModel.Design.MultilineStringEditor which can be used as follows: public class Stuff { [Editor(typeof(MultilineStringEditor), typeof(UITypeEditor))] public string MultiLineProperty { get; set; } } 回答2: No, you will need to create what's called a modal UI type editor. You'll need to create a class that inherits from UITypeEditor. This is basically a form that gets shown

ICustomTypeDescriptor, TypeDescriptionProvider, TypeConverter, and UITypeEditor

北战南征 提交于 2019-11-27 09:21:34
问题 I'm trying to get an overall understanding of how you use ICustomTypeDescriptor, TypeDescriptionProvider, TypeConverter, and UITypeEditor to change how a PropertyGrid displays and interfaces with an object. Can someone tell me if this is right, or if I missed any major concepts or points? I'm really just trying to understand why and when you would use each class. ICustomTypeDescriptor Implementing this interface in a class totaly overrides the native properties of a class and replaces them