Tag: propertygrid

C#PropertyGrid拖放

我正在尝试使用VS2005(.NET 2.0)实现对C#中的propertygrid的拖放支持。 propertygrid可以处理dragenter等事件,但似乎没有办法在拖动事件期间获取指针下的griditem。 到目前为止,我能够获得的最好的是使用selectedgriditem属性来检索自定义属性描述符并设置值,但这需要在开始拖放操作之前选择网格项。 有没有人有幸实现这个? 谢谢 :-)

WPF PropertyGrid支持多种选择

这个文档是否仍然有效或者我遗漏了什么? http://doc.xceedsoft.com/products/XceedWpfToolkit/Xceed.Wpf.Toolkit~Xceed.Wpf.Toolkit.PropertyGrid.PropertyGrid~SelectedObjects.html PropertyGrid控件似乎没有SelectedObjects或SelectedObjectsOverride成员。 我正在使用针对.NET Framework 4.0的Toolkit的最新版本(2.5)。 UPDATE @ faztp12的回答让我了解了。 对于寻找解决方案的其他人,请按照下列步骤操作: 将PropertyGrid的SelectedObject属性绑定到第一个选定的项目。 像这样的东西: 侦听PropertyValueChanged事件,并使用以下代码将属性值更新为所有选定对象。 private void PG_PropertyValueChanged(object sender, PropertyGrid.PropertyValueChangedEventArgs e) { var changedProperty = (PropertyItem)e.OriginalSource; foreach (var x in SelectedObjects) { //make sure that x supports this property var ProperProperty = x.GetType().GetProperty(changedProperty.PropertyDescriptor.Name); if (ProperProperty != null) { //fetch property descriptor from the actual declaring type, otherwise […]

PropertyGrid和动态对象类型

我正在编写一个GUI应用程序,我需要启用任意对象的编辑属性(它们的类型仅在运行时才知道)。 我决定使用PropertyGrid控件来启用此function。 我创建了以下类: [TypeConverter(typeof(ExpandableObjectConverter))] [DefaultPropertyAttribute(“Value”)] public class Wrapper { public Wrapper(object val) { m_Value = val; } private object m_Value; [NotifyParentPropertyAttribute(true)] [TypeConverter(typeof(ExpandableObjectConverter))] public object Value { get { return m_Value; } set { m_Value = value; } } } 当我得到一个我需要编辑的对象实例时,我为它创建了一个Wrapper并将其设置为所选对象: Wrapper wrap = new Wrapper(obj); propertyGrid.SelectedObject = wrap; 但是我遇到了以下问题 – 只有当obj的类型是某种自定义类型(即我自己定义的类,或者内置的复杂类型)时才能按预期工作,但是当obj是基元时则不行。 例如,如果我定义: [TypeConverter(typeof(ExpandableObjectConverter))] public class […]

如何在PropertyGrid中动态显示或隐藏属性?

我正在使用PropertyGrid来配置对象。 我需要能够隐藏或显示一些属性,具体取决于其他属性的值。 如何实现这一目标? 我知道Browsable属性,但它只能在编译时使用。

属性网格项和DoubleClick

我正在使用PropertyGrid控件来编辑应用程序中的某些对象。 我正在使用自定义TypeConverters和TypeEditors来获得更好的用户界面。 我对自定义TypeConverter的布尔属性有问题。 如果我有这个课程: public class MyClass { public string Name { get; set; } [System.ComponentModel.TypeConverter( typeof( BoolTypeConverter ) )] public bool Flag { get; set; } } 然后我在PropertyGrid中创建实例并将其设置为SelectedObject – 一切正常,直到用户在属性网格项上格式化“Flag”属性。 在DoubleClick发出此消息后: alt text http://tcks.wz.cz/property_grid_error.PNG TypeConverter类看起来: public class BoolTypeConverter : System.ComponentModel.TypeConverter { public const string TEXT_TRUE = “On”; public const string TEXT_FALSE = “Off”; public […]

找不到String的构造函数

如果我在包含List或Dictionary (使用GenericDictionaryEditor )的属性网格中有一个对象,当我单击属性旁边的详细信息并单击add时,会弹出一条消息说明找不到构造函数(列表)或找不到无参数构造函数(对于字典)。 我真的不了解编辑或财产网格,任何帮助将不胜感激。 [DataMember(Name=”FolderPaths”)] [ReadOnly(false)] [Description(“List of folder paths”)] [Editor(typeof(Wexman.Design.GenericDictionaryEditor), typeof(UITypeEditor))] [Wexman.Design.GenericDictionaryEditor(Title=”Folder Paths”)] public Dictionary FolderPaths { get; set; } 这个说没有为System.string []找到构造函数。 [DataMember(Name=”FolderPaths”)] [ReadOnly(false)] [Description(“List of folder paths”)] public List FolderPaths { get; set; }

更改propertygrid中只读属性的前景色

我正在使用WinForms属性网格来显示对象的属性。 但是,大多数属性都是只读的,因此显示为灰色而不是黑色。 有没有办法自定义使用的颜色? 我希望禁用的属性更容易阅读。 顺便说一句:我认为这个问题的答案可能与我想要做的事情有关。 但我不确定如何访问ControlPaint.DrawStringDisabled 。

C#选择CategorizedAlphabetical排序的ProperyGrid中的第一行

我有ProperyGrid加载分类PropertySpec并设置为CategorizedAlphabetical排序。 当表单运行类别时,类别中的项目将被排序。 令人讨厌的假象是PropertyGrid默认选择列表排序后的第一个项目,有时它会将视图滚动到选择。 如果项目列表很长,您最终会看到列表滚动到中间的某个位置。 由于可以在运行时创建PropertySpec,因此我希望始终在表单加载时显示列表的顶部。 PropertyGrid不会“轻易”公开集合,当然也不会按顺序排列。 谷歌搜索后,我相信这是不可能的?

PropertyGridvalidation

我有一个PropertyGrid 。 当我输入一个错误格式的值(即 – 一个整数项的字符串)时,我收到一条错误信息。 如果我单击“确定”,则坏值将一直保持到我更改它为止。 如果单击“取消”,则返回原始值。 我想控制按钮,因此单击“确定”也会将原始值设置回来,而不是像取消按钮那样显示错误值。 我怎样才能做到这一点?

带参数的C#UITypeEditor

我创建了一个自定义UITypeEditor ,它启动一个表单(StringSelector)来显示用户选择的字符串列表。 问题是这个表单需要知道要使用的StringManager(stringmanage只是一个包含List中允许的所有字符串的类)。 当我创建这个表单时,我将StringManager作为参数传递给构造函数,但我无法弄清楚如何使用UITypeEditor执行此操作。 下面是我当前的代码,它使用一个没有参数的构造函数,只是为了得到要显示的表单,但是显然没有字符串,因为我没有调用构造函数的参数版本。 如何将参数传递给UITypeEditor,然后我可以在EditValue函数中使用它? 非常感谢。 class StringSelectorEditor : UITypeEditor { public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) { return UITypeEditorEditStyle.Modal; } public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value) { IWindowsFormsEditorService svc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService; StringItem item = value as StringItem; if (svc != null) { // ###### How do I pass a […]