|
I have a problem with the PropertySpec serialization. The PropertySpec-class is marked to be serializable with the [Serializable] keyword. However, the serialization of the PropertySpec-instance fails, if the Attributes array member of the PropertySpec-class is not empty. For example, setting the ReadOnlyAttribute as it has been done in the example (PropertyBagTestForm.cs) prevents the serialization of the given PropertySpec.
Is there any graceful workaround to this problem? I am attempting to use binary serialization so that I could store the PropertySpecs to the database.
best regards,
mr T.
|
|
|
|
|
I have the exact same problem. It says that system.component.readonlyattribute or browsableattribute are not marked as serializable.
"The type System.ComponentModel.ReadOnlyAttribute in Assembly System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 is not marked as serializable."
Any Luck?
Miky VC
|
|
|
|
|
hey in the propertyspec do the following for Attributes array
--------------> [NonSerialized()]
private Attribute[] attributes;
but with this u need to update the attribute once you reopen the Serialized object
Sachin V.
Savy
|
|
|
|
|
Has somebody solved this problem jet?
My Task
1a) is to write a class to store Ini-File Data (diffrent class for each application that uses Ini_files (hard coded properties)
1b) is to write a class to read and write all the Data ( de-/serialize ) derived form 1a)
this (2nd class) is the same for all aplications !
I found this PropertyBag and think it is great, ... but i can't serialize it ;(
And the Class found at
http://www.codeproject.com/soap/xmlsettings.asp[^]
is perfect for serializig but it's a hard core source bloat!!
If someone knows this problem or solved it, please paste a LINK or a solution.
I don't think it is too hard to combine both classes, but I just can't handle them ...
Please Help!
|
|
|
|
|
Dear, Sir.
Is it possible to change BackColor and Font of some cell in propertyGrid Control.
If possible, how to do?
Thank You.
|
|
|
|
|
Would it be possible to have a property with a Type that is not defined in the same assembly as the PropertyBag. For example, the property bag is in a class library (DLL), and an application uses the PropertyBag (or Table, for all I care) with a type declared in another class library.
Thanx in advance! (see sample pseudo-code)
'---------------------------------
' Type Class Library
'---------------------------------
Pulbic Enum MyType
...
End Enum
'---------------------------------
' PropertyBag Class Library
'---------------------------------
Pulbic Class PropertyBag
...
End Class
'---------------------------------
' Application
'---------------------------------
* Creates a new PropertyTable with MyType enum properties.
|
|
|
|
|
The following codes produce a "blank" display. The "OnGetValue" was not ever called.
Assigning newprop.fPropSheet.SelectedObject to any of the "normal" object works just fine.
Thanks!
Wen Yu
Dim bag3 As PropertyTable = New PropertyTable()
bag3.Properties.Add(New PropertySpec("Number", "System.Int64", Nothing, "A big number.", 1234567890L))
'// Create a property that uses additional attributes.
Dim ps As PropertySpec = New PropertySpec("Can't Touch This", "System.String", Nothing, "This property is read-only.", "Some Default String")
ps.Attributes = New System.Attribute() {ReadOnlyAttribute.Yes}
bag3.Properties.Add(ps)
bag3.DefaultProperty = "Name"
'// Assign values to the properties above.
bag3("Number") = 1234567890L
bag3("Can't Touch This") = "Some Default String"
' newprop is a TabPage with PropertyGrid as the only control
newprop.fPropSheet.SelectedObject = bag3
|
|
|
|
|
Anyone have an example of using this with a collection? I'd like to have the elipses and pop up the window that the user can use to add multiple items.
|
|
|
|
|
hen I create an object from my class locally and assign it to a
PropertyGrid, everything works fine.
When I create remote object from the same class and assign it to
ProperyGrid, I get an exception: "Attempted to call a method declared on
type System.ComponentModel.ICustomTypeDescriptor on an object which
exposes MyNamespace.MyClass."
I tried implementing ICustomTypeDescriptor myself, but this only results
in another exception because one of the ICustomTypeDescriptor methods
returns a .Net Framework-defined type that is not marked serializable.
If it matters, the remote object is server-activated, and the proxy is
acquired via Activator.GetObject().
Questions:
Is there a way to prevent the PropertyGrid from treating the proxy as if
it supported ICustomTypeDescriptor?
Is there a proxy type that actually does implement ICustomTypeDescriptor?
Is there some other way around this problem?
Thanks,
cao
China
|
|
|
|
|
I have a couple of properties that are derived from ExpandableObjectConverter, they all work ok, but i would like them to be displayed expanded when the property grid is displayed as opposed to collapsed which appears to be the default
any ideas?
|
|
|
|
|
Is it possible to take the PropertyBag collection, and transform only a part of it (eg. from a specific index in the collection til the end) to an array. I know that PropertyBag supports a method that can transform the entire collection into an array (PropertyBag.Properties.ToArray()), but can it support, in some way, transforming partitions of this collection? Thanks for the help.
BTW, a very nice program indeed. Keep up the good work.
|
|
|
|
|
Is it possible to set a Property Category description?
That way when you click on a catgegory it will display some text a the bottom of the PropertyGrid
|
|
|
|
|
'*******************************************************************
' *
' * PropertyBag.vb
' * --------------
' * Copyright (C) 2003 Tony Allowatt / Loic Barbou
' * THE SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS", WITHOUT WARRANTY
' * OF ANY KIND, EXPRESS OR IMPLIED. IN NO EVENT SHALL THE AUTHOR BE
' * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY ARISING FROM,
' * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF THIS
' * SOFTWARE.
' *
' * Public types defined in this file:
' * ----------------------------------
' * class PropertySpec
' * class PropertySpecEventArgs
' * delegate PropertySpecEventHandler
' * class PropertyBag
' * class PropertyBag.PropertySpecCollection
' * class PropertyTable
' *
' *******************************************************************
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Drawing.Design
_
'/
'/ Represents a single property in a PropertySpec.
'/
Public Class PropertySpec
Private m_attributes() As Attribute
Private m_category As String
Private m_defaultValue As Object
Private m_description As String
Private editor As String
Private m_name As String
Private type As String
Private typeConverter As String
'/
'/ Initializes a new instance of the PropertySpec class.
'/
'/ <param name="name" />The name of the property displayed in the property grid.
'/ <param name="type" />The fully qualified name of the type of the property.
Public Sub New(ByVal name As String, ByVal type As String)
MyClass.New(name, type, Nothing, Nothing, Nothing)
End Sub 'New
'/
'/ Initializes a new instance of the PropertySpec class.
'/
'/ <param name="name" />The name of the property displayed in the property grid.
'/ <param name="type" />A Type that represents the type of the property.
Public Sub New(ByVal name As String, ByVal type As type)
MyClass.New(name, type.AssemblyQualifiedName, Nothing, Nothing, Nothing)
End Sub 'New
'/
'/ Initializes a new instance of the PropertySpec class.
'/
'/ <param name="name" />The name of the property displayed in the property grid.
'/ <param name="type" />The fully qualified name of the type of the property.
'/ <param name="category" />The category under which the property is displayed in the
'/ property grid.
Public Sub New(ByVal name As String, ByVal type As String, ByVal category As String)
MyClass.New(name, type, category, Nothing, Nothing)
End Sub 'New
'/
'/ Initializes a new instance of the PropertySpec class.
'/
'/ <param name="name" />The name of the property displayed in the property grid.
'/ <param name="type" />A Type that represents the type of the property.
'/ <param name="category" />
Public Sub New(ByVal name As String, ByVal type As type, ByVal category As String)
MyClass.New(name, type.AssemblyQualifiedName, category, Nothing, Nothing)
End Sub 'New
'/
'/ Initializes a new instance of the PropertySpec class.
'/
'/ <param name="name" />The name of the property displayed in the property grid.
'/ <param name="type" />The fully qualified name of the type of the property.
'/ <param name="category" />The category under which the property is displayed in the
'/ property grid.
'/ <param name="description" />A string that is displayed in the help area of the
'/ property grid.
Public Sub New(ByVal name As String, ByVal type As String, ByVal category As String, ByVal description As String)
MyClass.New(name, type, category, description, Nothing)
End Sub 'New
'/
'/ Initializes a new instance of the PropertySpec class.
'/
'/ <param name="name" />The name of the property displayed in the property grid.
'/ <param name="type" />A Type that represents the type of the property.
'/ <param name="category" />The category under which the property is displayed in the
'/ property grid.
'/ <param name="description" />A string that is displayed in the help area of the
'/ property grid.
Public Sub New(ByVal name As String, ByVal type As type, ByVal category As String, ByVal description As String)
MyClass.New(name, type.AssemblyQualifiedName, category, description, Nothing)
End Sub 'New
'/
'/ Initializes a new instance of the PropertySpec class.
'/
'/ <param name="name" />The name of the property displayed in the property grid.
'/ <param name="type" />The fully qualified name of the type of the property.
'/ <param name="category" />The category under which the property is displayed in the
'/ property grid.
'/ <param name="description" />A string that is displayed in the help area of the
'/ property grid.
'/ <param name="defaultValue" />The default value of the property, or null if there is
'/ no default value.
Public Sub New(ByVal name As String, ByVal type As String, ByVal category As String, ByVal description As String, ByVal defaultValue As Object)
Me.m_name = name
Me.type = type
Me.m_category = category
Me.m_description = description
Me.m_defaultValue = defaultValue
Me.m_attributes = Nothing
End Sub 'New
'/
'/ Initializes a new instance of the PropertySpec class.
'/
'/ <param name="name" />The name of the property displayed in the property grid.
'/ <param name="type" />A Type that represents the type of the property.
'/ <param name="category" />The category under which the property is displayed in the
'/ property grid.
'/ <param name="description" />A string that is displayed in the help area of the
'/ property grid.
'/ <param name="defaultValue" />The default value of the property, or null if there is
'/ no default value.
Public Sub New(ByVal name As String, ByVal type As type, ByVal category As String, ByVal description As String, ByVal defaultValue As Object)
MyClass.New(name, type.AssemblyQualifiedName, category, description, defaultValue)
End Sub 'New
'/
'/ Initializes a new instance of the PropertySpec class.
'/
'/ <param name="name" />The name of the property displayed in the property grid.
'/ <param name="type" />The fully qualified name of the type of the property.
'/ <param name="category" />The category under which the property is displayed in the
'/ property grid.
'/ <param name="description" />A string that is displayed in the help area of the
'/ property grid.
'/ <param name="defaultValue" />The default value of the property, or null if there is
'/ no default value.
'/ <param name="editor" />The fully qualified name of the type of the editor for this
'/ property. This type must derive from UITypeEditor.
'/ <param name="typeConverter" />The fully qualified name of the type of the type
'/ converter for this property. This type must derive from TypeConverter.
Public Sub New(ByVal name As String, ByVal type As String, ByVal category As String, ByVal description As String, ByVal defaultValue As Object, ByVal editor As String, ByVal typeConverter As String)
MyClass.New(name, type, category, description, defaultValue)
Me.editor = editor
Me.typeConverter = typeConverter
End Sub 'New
'/
'/ Initializes a new instance of the PropertySpec class.
'/
'/ <param name="name" />The name of the property displayed in the property grid.
'/ <param name="type" />A Type that represents the type of the property.
'/ <param name="category" />The category under which the property is displayed in the
'/ property grid.
'/ <param name="description" />A string that is displayed in the help area of the
'/ property grid.
'/ <param name="defaultValue" />The default value of the property, or null if there is
'/ no default value.
'/ <param name="editor" />The fully qualified name of the type of the editor for this
'/ property. This type must derive from UITypeEditor.
'/ <param name="typeConverter" />The fully qualified name of the type of the type
'/ converter for this property. This type must derive from TypeConverter.
Public Sub New(ByVal name As String, ByVal type As type, ByVal category As String, ByVal description As String, ByVal defaultValue As Object, ByVal editor As String, ByVal typeConverter As String)
MyClass.New(name, type.AssemblyQualifiedName, category, description, defaultValue, editor, typeConverter)
End Sub 'New
'/
'/ Initializes a new instance of the PropertySpec class.
'/
'/ <param name="name" />The name of the property displayed in the property grid.
'/ <param name="type" />The fully qualified name of the type of the property.
'/ <param name="category" />The category under which the property is displayed in the
'/ property grid.
'/ <param name="description" />A string that is displayed in the help area of the
'/ property grid.
'/ <param name="defaultValue" />The default value of the property, or null if there is
'/ no default value.
'/ <param name="editor" />The Type that represents the type of the editor for this
'/ property. This type must derive from UITypeEditor.
'/ <param name="typeConverter" />The fully qualified name of the type of the type
'/ converter for this property. This type must derive from TypeConverter.
Public Sub New(ByVal name As String, ByVal type As String, ByVal category As String, ByVal description As String, ByVal defaultValue As Object, ByVal editor As type, ByVal typeConverter As String)
MyClass.New(name, type, category, description, defaultValue, editor.AssemblyQualifiedName, typeConverter)
End Sub 'New
'/
'/ Initializes a new instance of the PropertySpec class.
'/
'/ <param name="name" />The name of the property displayed in the property grid.
'/ <param name="type" />A Type that represents the type of the property.
'/ <param name="category" />The category under which the property is displayed in the
'/ property grid.
'/ <param name="description" />A string that is displayed in the help area of the
'/ property grid.
'/ <param name="defaultValue" />The default value of the property, or null if there is
'/ no default value.
'/ <param name="editor" />The Type that represents the type of the editor for this
'/ property. This type must derive from UITypeEditor.
'/ <param name="typeConverter" />The fully qualified name of the type of the type
'/ converter for this property. This type must derive from TypeConverter.
Public Sub New(ByVal name As String, ByVal type As type, ByVal category As String, ByVal description As String, ByVal defaultValue As Object, ByVal editor As type, ByVal typeConverter As String)
MyClass.New(name, type.AssemblyQualifiedName, category, description, defaultValue, editor.AssemblyQualifiedName, typeConverter)
End Sub 'New
'/
'/ Initializes a new instance of the PropertySpec class.
'/
'/ <param name="name" />The name of the property displayed in the property grid.
'/ <param name="type" />The fully qualified name of the type of the property.
'/ <param name="category" />The category under which the property is displayed in the
'/ property grid.
'/ <param name="description" />A string that is displayed in the help area of the
'/ property grid.
'/ <param name="defaultValue" />The default value of the property, or null if there is
'/ no default value.
'/ <param name="editor" />The fully qualified name of the type of the editor for this
'/ property. This type must derive from UITypeEditor.
'/ <param name="typeConverter" />The Type that represents the type of the type
'/ converter for this property. This type must derive from TypeConverter.
Public Sub New(ByVal name As String, ByVal type As String, ByVal category As String, ByVal description As String, ByVal defaultValue As Object, ByVal editor As String, ByVal typeConverter As type)
MyClass.New(name, type, category, description, defaultValue, editor, typeConverter.AssemblyQualifiedName)
End Sub 'New
'/
'/ Initializes a new instance of the PropertySpec class.
'/
'/ <param name="name" />The name of the property displayed in the property grid.
'/ <param name="type" />A Type that represents the type of the property.
'/ <param name="category" />The category under which the property is displayed in the
'/ property grid.
'/ <param name="description" />A string that is displayed in the help area of the
'/ property grid.
'/ <param name="defaultValue" />The default value of the property, or null if there is
'/ no default value.
'/ <param name="editor" />The fully qualified name of the type of the editor for this
'/ property. This type must derive from UITypeEditor.
'/ <param name="typeConverter" />The Type that represents the type of the type
'/ converter for this property. This type must derive from TypeConverter.
Public Sub New(ByVal name As String, ByVal type As type, ByVal category As String, ByVal description As String, ByVal defaultValue As Object, ByVal editor As String, ByVal typeConverter As type)
MyClass.New(name, type.AssemblyQualifiedName, category, description, defaultValue, editor, typeConverter.AssemblyQualifiedName)
End Sub 'New
'/
'/ Initializes a new instance of the PropertySpec class.
'/
'/ <param name="name" />The name of the property displayed in the property grid.
'/ <param name="type" />The fully qualified name of the type of the property.
'/ <param name="category" />The category under which the property is displayed in the
'/ property grid.
'/ <param name="description" />A string that is displayed in the help area of the
'/ property grid.
'/ <param name="defaultValue" />The default value of the property, or null if there is
'/ no default value.
'/ <param name="editor" />The Type that represents the type of the editor for this
'/ property. This type must derive from UITypeEditor.
'/ <param name="typeConverter" />The Type that represents the type of the type
'/ converter for this property. This type must derive from TypeConverter.
Public Sub New(ByVal name As String, ByVal type As String, ByVal category As String, ByVal description As String, ByVal defaultValue As Object, ByVal editor As type, ByVal typeConverter As type)
MyClass.New(name, type, category, description, defaultValue, editor.AssemblyQualifiedName, typeConverter.AssemblyQualifiedName)
End Sub 'New
'/
'/ Initializes a new instance of the PropertySpec class.
'/
'/ <param name="name" />The name of the property displayed in the property grid.
'/ <param name="type" />A Type that represents the type of the property.
'/ <param name="category" />The category under which the property is displayed in the
'/ property grid.
'/ <param name="description" />A string that is displayed in the help area of the
'/ property grid.
'/ <param name="defaultValue" />The default value of the property, or null if there is
'/ no default value.
'/ <param name="editor" />The Type that represents the type of the editor for this
'/ property. This type must derive from UITypeEditor.
'/ <param name="typeConverter" />The Type that represents the type of the type
'/ converter for this property. This type must derive from TypeConverter.
Public Sub New(ByVal name As String, ByVal type As type, ByVal category As String, ByVal description As String, ByVal defaultValue As Object, ByVal editor As type, ByVal typeConverter As type)
MyClass.New(name, type.AssemblyQualifiedName, category, description, defaultValue, editor.AssemblyQualifiedName, typeConverter.AssemblyQualifiedName)
End Sub 'New
'/
'/ Gets or sets a collection of additional Attributes for this property. This can
'/ be used to specify attributes beyond those supported intrinsically by the
'/ PropertySpec class, such as ReadOnly and Browsable.
'/
Public Property Attributes() As Attribute()
Get
Return m_attributes
End Get
Set(ByVal Value As Attribute())
m_attributes = Value
End Set
End Property
'/
'/ Gets or sets the category name of this property.
'/
Public Property Category() As String
Get
Return m_category
End Get
Set(ByVal Value As String)
m_category = Value
End Set
End Property
'/
'/ Gets or sets the fully qualified name of the type converter
'/ type for this property.
'/
Public Property ConverterTypeName() As String
Get
Return typeConverter
End Get
Set(ByVal Value As String)
typeConverter = Value
End Set
End Property
'/
'/ Gets or sets the default value of this property.
'/
Public Property DefaultValue() As Object
Get
Return m_defaultValue
End Get
Set(ByVal Value As Object)
m_defaultValue = Value
End Set
End Property
'/
'/ Gets or sets the help text description of this property.
'/
Public Property Description() As String
Get
Return m_description
End Get
Set(ByVal Value As String)
m_description = Value
End Set
End Property
'/
'/ Gets or sets the fully qualified name of the editor type for
'/ this property.
'/
Public Property EditorTypeName() As String
Get
Return editor
End Get
Set(ByVal Value As String)
editor = Value
End Set
End Property
'/
'/ Gets or sets the name of this property.
'/
Public Property Name() As String
Get
Return m_name
End Get
Set(ByVal Value As String)
m_name = Value
End Set
End Property
'/
'/ Gets or sets the fully qualfied name of the type of this
'/ property.
'/
Public Property TypeName() As String
Get
Return type
End Get
Set(ByVal Value As String)
type = Value
End Set
End Property
End Class 'PropertySpec
_
'/
'/ Provides data for the GetValue and SetValue events of the PropertyBag class.
'/
Public Class PropertySpecEventArgs
Inherits EventArgs
Private m_property As PropertySpec
Private val As Object
'/
'/ Initializes a new instance of the PropertySpecEventArgs class.
'/
'/ <param name="property" />The PropertySpec that represents the property whose
'/ value is being requested or set.
'/ <param name="val" />The current value of the property.
Public Sub New(ByVal [property] As PropertySpec, ByVal val As Object)
Me.m_property = [property]
Me.val = val
End Sub 'New
'/
'/ Gets the PropertySpec that represents the property whose value is being
'/ requested or set.
'/
Public ReadOnly Property [Property]() As PropertySpec
Get
Return m_property
End Get
End Property
'/
'/ Gets or sets the current value of the property.
'/
Public Property Value() As Object
Get
Return val
End Get
Set(ByVal Value As Object)
val = Value
End Set
End Property
End Class 'PropertySpecEventArgs
'/
'/ Represents the method that will handle the GetValue and SetValue events of the
'/ PropertyBag class.
'/
Public Delegate Sub PropertySpecEventHandler(ByVal sender As Object, ByVal e As PropertySpecEventArgs)
'_
'/
'/ Represents a collection of custom properties that can be selected into a
'/ PropertyGrid to provide functionality beyond that of the simple reflection
'/ normally used to query an object's properties.
'/
Public Class PropertyBag
Implements ICustomTypeDescriptor 'ToDo: Add Implements Clauses for implementation methods of these interface(s)
'
'ToDo: Error processing original source shown below
'
'
'-----^--- Pre-processor directives not translated
'/
'
'ToDo: Error processing original source shown below
'
'
'--^--- Unexpected pre-processor directive
'/ Encapsulates a collection of PropertySpec objects.
'/ \
<serializable()> _
Public Class PropertySpecCollection
Implements IList 'ToDo: Add Implements Clauses for implementation methods of these interface(s)
Private innerArray As ArrayList
'/
'/ Initializes a new instance of the PropertySpecCollection class.
'/
Public Sub New()
innerArray = New ArrayList
End Sub 'New
'/
'/ Gets the number of elements in the PropertySpecCollection.
'/
'/ <value>
'/ The number of elements contained in the PropertySpecCollection.
'/
Public ReadOnly Property Count() As Integer Implements IList.count
Get
Return innerArray.Count
End Get
End Property
'/
'/ Gets a value indicating whether the PropertySpecCollection has a fixed size.
'/
'/ <value>
'/ true if the PropertySpecCollection has a fixed size; otherwise, false.
'/
Public ReadOnly Property IsFixedSize() As Boolean Implements IList.isfixedsize
Get
Return False
End Get
End Property
'/
'/ Gets a value indicating whether the PropertySpecCollection is read-only.
'/
Public ReadOnly Property IsReadOnly() As Boolean Implements IList.isreadonly
Get
Return False
End Get
End Property
'/
'/ Gets a value indicating whether access to the collection is synchronized (thread-safe).
'/
'/ <value>
'/ true if access to the PropertySpecCollection is synchronized (thread-safe); otherwise, false.
'/
Public ReadOnly Property IsSynchronized() As Boolean Implements IList.IsSynchronized
Get
Return False
End Get
End Property
'/
'/ Gets an object that can be used to synchronize access to the collection.
'/
'/ <value>
'/ An object that can be used to synchronize access to the collection.
'/
'ReadOnly Property ICollection.SyncRoot() As Object
ReadOnly Property SyncRoot() As Object Implements ICollection.SyncRoot
Get
Return Nothing
End Get
End Property
'/
'/ Gets or sets the element at the specified index.
'/ In C#, this property is the indexer for the PropertySpecCollection class.
'/
'/ <param name="index" />The zero-based index of the element to get or set.
'/ <value>
'/ The element at the specified index.
'/
'Default Public Property Item(ByVal index As Integer) As PropertySpec
' Get
' Return CType(innerArray(index), PropertySpec)
' End Get
' Set(ByVal Value As PropertySpec)
' innerArray(index) = Value
' End Set
'End Property
Default Public Property Item(ByVal index As Integer) As Object Implements IList.Item
Get
Return CType(innerArray(index), PropertySpec)
End Get
Set(ByVal Value As Object)
innerArray(index) = Value
End Set
End Property
'Public Property Item(ByVal index As Integer) As Object Implements IList.item
' Get
' Return CType(innerArray(index), Object)
' End Get
' Set(ByVal Value As Object)
' innerArray(index) = Value
' End Set
'End Property
'/
'/ Adds a PropertySpec to the end of the PropertySpecCollection.
'/
'/ <param name="value" />The PropertySpec to be added to the end of the PropertySpecCollection.
'/ <returns>The PropertySpecCollection index at which the value has been added.
Public Function Add(ByVal value As PropertySpec) As Integer
Dim index As Integer = innerArray.Add(value)
Return index
End Function 'Add
'/
'/ Adds the elements of an array of PropertySpec objects to the end of the PropertySpecCollection.
'/
'/ <param name="array" />The PropertySpec array whose elements should be added to the end of the
'/ PropertySpecCollection.
Public Sub AddRange(ByVal array() As PropertySpec)
innerArray.AddRange(array)
End Sub 'AddRange
'/
'/ Removes all elements from the PropertySpecCollection.
'/
Public Sub Clear() Implements IList.clear
innerArray.Clear()
End Sub 'Clear
'/
'/ Determines whether a PropertySpec is in the PropertySpecCollection.
'/
'/ <param name="item" />The PropertySpec to locate in the PropertySpecCollection. The element to locate
'/ can be a null reference (Nothing in Visual Basic).
'/ <returns>true if item is found in the PropertySpecCollection; otherwise, false.
Public Overloads Function Contains(ByVal item As PropertySpec) As Boolean
Return innerArray.Contains(item)
End Function 'Contains
'/
'/ Determines whether a PropertySpec with the specified name is in the PropertySpecCollection.
'/
'/ <param name="name" />The name of the PropertySpec to locate in the PropertySpecCollection.
'/ <returns>true if item is found in the PropertySpecCollection; otherwise, false.
Public Overloads Function Contains(ByVal name As String) As Boolean
Dim spec As PropertySpec
For Each spec In innerArray
If spec.Name = name Then
Return True
End If
Next spec
Return False
End Function 'Contains
'/
'/ Copies the entire PropertySpecCollection to a compatible one-dimensional Array, starting at the
'/ beginning of the target array.
'/
'/ <param name="array" />The one-dimensional Array that is the destination of the elements copied
'/ from PropertySpecCollection. The Array must have zero-based indexing.
Public Overloads Sub CopyTo(ByVal array() As PropertySpec)
innerArray.CopyTo(array)
End Sub 'CopyTo
'/
'/ Copies the PropertySpecCollection or a portion of it to a one-dimensional array.
'/
'/ <param name="array" />The one-dimensional Array that is the destination of the elements copied
'/ from the collection.
'/ <param name="index" />The zero-based index in array at which copying begins.
Public Overloads Sub CopyTo(ByVal array() As PropertySpec, ByVal index As Integer)
innerArray.CopyTo(array, index)
End Sub 'CopyTo
'/
'/ Returns an enumerator that can iterate through the PropertySpecCollection.
'/
'/ <returns>An IEnumerator for the entire PropertySpecCollection.
Public Function GetEnumerator() As IEnumerator Implements IList.getenumerator
Return innerArray.GetEnumerator()
End Function 'GetEnumerator
'/
'/ Searches for the specified PropertySpec and returns the zero-based index of the first
'/ occurrence within the entire PropertySpecCollection.
'/
'/ <param name="value" />The PropertySpec to locate in the PropertySpecCollection.
'/ <returns>The zero-based index of the first occurrence of value within the entire PropertySpecCollection,
'/ if found; otherwise, -1.
Public Overloads Function IndexOf(ByVal value As PropertySpec) As Integer
Return innerArray.IndexOf(value)
End Function 'IndexOf
'/
'/ Searches for the PropertySpec with the specified name and returns the zero-based index of
'/ the first occurrence within the entire PropertySpecCollection.
'/
'/ <param name="name" />The name of the PropertySpec to locate in the PropertySpecCollection.
'/ <returns>The zero-based index of the first occurrence of value within the entire PropertySpecCollection,
'/ if found; otherwise, -1.
Public Overloads Function IndexOf(ByVal name As String) As Integer
Dim i As Integer = 0
Dim spec As PropertySpec
For Each spec In innerArray
If spec.Name = name Then
Return i
End If
i += 1
Next spec
Return -1
End Function 'IndexOf
'/
'/ Inserts a PropertySpec object into the PropertySpecCollection at the specified index.
'/
'/ <param name="index" />The zero-based index at which value should be inserted.
'/ <param name="value" />The PropertySpec to insert.
Public Sub Insert(ByVal index As Integer, ByVal value As PropertySpec)
innerArray.Insert(index, value)
End Sub 'Insert
'/
'/ Removes the first occurrence of a specific object from the PropertySpecCollection.
'/
'/ <param name="obj" />The PropertySpec to remove from the PropertySpecCollection.
Public Overloads Sub Remove(ByVal obj As PropertySpec)
innerArray.Remove(obj)
End Sub 'Remove
'/
'/ Removes the property with the specified name from the PropertySpecCollection.
'/
'/ <param name="name" />The name of the PropertySpec to remove from the PropertySpecCollection.
Public Overloads Sub Remove(ByVal name As String)
Dim index As Integer = IndexOf(name)
RemoveAt(index)
End Sub 'Remove
'/
'/ Removes the object at the specified index of the PropertySpecCollection.
'/
'/ <param name="index" />The zero-based index of the element to remove.
Public Sub RemoveAt(ByVal index As Integer) Implements IList.removeat
innerArray.RemoveAt(index)
End Sub 'RemoveAt
'/
'/ Copies the elements of the PropertySpecCollection to a new PropertySpec array.
'/
'/ <returns>A PropertySpec array containing copies of the elements of the PropertySpecCollection.
Public Function ToArray() As PropertySpec()
Return CType(innerArray.ToArray(GetType(PropertySpec)), PropertySpec())
End Function 'ToArray
'
'ToDo: Error processing original source shown below
'
'
'------^--- Pre-processor directives not translated
'/
'
'ToDo: Error processing original source shown below
'
'
'--^--- Unexpected pre-processor directive
'/ This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.
'/
'Sub ICollection.CopyTo(array As Array, index As Integer)
Overloads Sub CopyTo(ByVal array As Array, ByVal index As Integer) Implements ICollection.CopyTo
CopyTo(CType(array, PropertySpec()), index)
End Sub 'ICollection.CopyTo
'/
'/ This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.
'/
Function Add(ByVal value As Object) As Integer Implements IList.add
Return Add(CType(value, PropertySpec))
End Function 'IList.Add
'/
'/ This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.
'/
Overloads Function Contains(ByVal obj As Object) As Boolean Implements IList.contains
Return Contains(CType(obj, PropertySpec))
End Function 'IList.Contains
'/
'/ This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.
'/
Property IList(ByVal index As Integer) As Object
Get
Return CType(Me, PropertySpecCollection)(index)
End Get
Set(ByVal Value As Object)
CType(Me, PropertySpecCollection)(index) = CType(Value, PropertySpec)
End Set
End Property
'/
'/ This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.
'/
Overloads Function IndexOf(ByVal obj As Object) As Integer Implements IList.IndexOf
Return IndexOf(CType(obj, PropertySpec))
End Function 'IList.IndexOf
'/
'/ This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.
'/
Sub Insert(ByVal index As Integer, ByVal value As Object) Implements IList.insert
Insert(index, CType(value, PropertySpec))
End Sub 'IList.Insert
'/
'/ This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.
'/
Overloads Sub Remove(ByVal value As Object) Implements IList.Remove
Remove(CType(value, PropertySpec))
End Sub 'IList.Remove
End Class 'PropertySpecCollection
'_ '
'ToDo: Error processing original source shown below
'
'
'------^--- Pre-processor directives not translated
'
'ToDo: Error processing original source shown below
'
'
'--^--- Unexpected pre-processor directive
'
'ToDo: Error processing original source shown below
'
'
'-----^--- Pre-processor directives not translated
Private Class PropertySpecDescriptor
Inherits PropertyDescriptor '
'ToDo: Error processing original source shown below
'
'
'--^--- Unexpected pre-processor directive
'
'ToDo: Error processing original source shown below
'
'
'-----^--- Pre-processor directives not translated
'
'ToDo: Error processing original source shown below
'
'
'--^--- Unexpected pre-processor directive
Private bag As PropertyBag
Private item As PropertySpec
Public Sub New(ByVal item As PropertySpec, ByVal bag As PropertyBag, ByVal name As String, ByVal attrs() As Attribute)
MyBase.New(name, attrs)
Me.bag = bag
Me.item = item
End Sub 'New
Public Overrides ReadOnly Property ComponentType() As Type
Get
Return item.GetType()
End Get
End Property
Public Overrides ReadOnly Property IsReadOnly() As Boolean
Get
Return Attributes.Matches(ReadOnlyAttribute.Yes)
End Get
End Property
Public Overrides ReadOnly Property PropertyType() As Type
Get
Return Type.GetType(item.TypeName)
End Get
End Property
Public Overrides Function CanResetValue(ByVal component As Object) As Boolean
If item.DefaultValue Is Nothing Then
Return False
Else
Return Not Me.GetValue(component).Equals(item.DefaultValue)
End If
End Function 'CanResetValue
Public Overrides Function GetValue(ByVal component As Object) As Object
' Have the property bag raise an event to get the current value
' of the property.
Dim e As New PropertySpecEventArgs(item, Nothing)
bag.OnGetValue(e)
Return e.Value
End Function 'GetValue
Public Overrides Sub ResetValue(ByVal component As Object)
SetValue(component, item.DefaultValue)
End Sub 'ResetValue
Public Overrides Sub SetValue(ByVal component As Object, ByVal value As Object)
' Have the property bag raise an event to set the current value
' of the property.
Dim e As New PropertySpecEventArgs(item, value)
bag.OnSetValue(e)
End Sub 'SetValue
Public Overrides Function ShouldSerializeValue(ByVal component As Object) As Boolean
Dim val As Object = Me.GetValue(component)
If item.DefaultValue Is Nothing And val Is Nothing Then
Return False
Else
Return Not val.Equals(item.DefaultValue)
End If
End Function 'ShouldSerializeValue
End Class 'PropertySpecDescriptor '
'ToDo: Error processing original source shown below
'
'
'-----^--- Pre-processor directives not translated
Private m_defaultProperty As String '
'ToDo: Error processing original source shown below
'
'
'--^--- Unexpected pre-processor directive
Private m_properties As PropertySpecCollection
'/
'/ Initializes a new instance of the PropertyBag class.
'/
Public Sub New()
m_defaultProperty = Nothing
m_properties = New PropertySpecCollection
End Sub 'New
'/
'/ Gets or sets the name of the default property in the collection.
'/
Public Property DefaultProperty() As String
Get
Return m_defaultProperty
End Get
Set(ByVal Value As String)
m_defaultProperty = Value
End Set
End Property
'/
'/ Gets the collection of properties contained within this PropertyBag.
'/
Public ReadOnly Property Properties() As PropertySpecCollection
Get
Return m_properties
End Get
End Property
'/
'/ Occurs when a PropertyGrid requests the value of a property.
'/
Public Event GetValue As PropertySpecEventHandler
'/
'/ Occurs when the user changes the value of a property in a PropertyGrid.
'/
Public Event SetValue As PropertySpecEventHandler
'/
'/ Raises the GetValue event.
'/
'/ <param name="e" />A PropertySpecEventArgs that contains the event data.
Protected Overridable Sub OnGetValue(ByVal e As PropertySpecEventArgs)
' If Not (GetValue Is Nothing) Then
RaiseEvent GetValue(Me, e)
'End If
End Sub 'OnGetValue
'/
'/ Raises the SetValue event.
'/
'/ <param name="e" />A PropertySpecEventArgs that contains the event data.
Protected Overridable Sub OnSetValue(ByVal e As PropertySpecEventArgs)
' If Not (SetValue Is Nothing) Then
RaiseEvent SetValue(Me, e)
' End If
End Sub 'OnSetValue
'
'ToDo: Error processing original source shown below
'
'
'-----^--- Pre-processor directives not translated
' Most of the functions required by the ICustomTypeDescriptor are
'
'ToDo: Error processing original source shown below
'
'
'--^--- Unexpected pre-processor directive
' merely pssed on to the default TypeDescriptor for this type,
' which will do something appropriate. The exceptions are noted
' below.
Function GetAttributes() As AttributeCollection Implements ICustomTypeDescriptor.GetAttributes
Return TypeDescriptor.GetAttributes(Me, True)
End Function 'ICustomTypeDescriptor.GetAttributes
Function GetClassName() As String Implements ICustomTypeDescriptor.GetClassName
Return TypeDescriptor.GetClassName(Me, True)
End Function 'ICustomTypeDescriptor.GetClassName
Function GetComponentName() As String Implements ICustomTypeDescriptor.GetComponentName
Return TypeDescriptor.GetComponentName(Me, True)
End Function 'ICustomTypeDescriptor.GetComponentName
Function GetConverter() As TypeConverter Implements ICustomTypeDescriptor.GetConverter
Return TypeDescriptor.GetConverter(Me, True)
End Function 'ICustomTypeDescriptor.GetConverter
Function GetDefaultEvent() As EventDescriptor Implements ICustomTypeDescriptor.GetDefaultEvent
Return TypeDescriptor.GetDefaultEvent(Me, True)
End Function 'ICustomTypeDescriptor.GetDefaultEvent
Function GetDefaultProperty() As PropertyDescriptor Implements ICustomTypeDescriptor.GetDefaultProperty
' This function searches the property list for the property
' with the same name as the DefaultProperty specified, and
' returns a property descriptor for it. If no property is
' found that matches DefaultProperty, a null reference is
' returned instead.
Dim propertySpec As PropertySpec = Nothing
If Not (DefaultProperty Is Nothing) Then
Dim index As Integer = Properties.IndexOf(DefaultProperty)
propertySpec = Properties(index)
End If
If Not (propertySpec Is Nothing) Then
Return New PropertySpecDescriptor(propertySpec, Me, propertySpec.Name, Nothing)
Else
Return Nothing
End If
End Function 'ICustomTypeDescriptor.GetDefaultProperty
Function GetEditor(ByVal editorBaseType As Type) As Object Implements ICustomTypeDescriptor.GetEditor
Return TypeDescriptor.GetEditor(Me, editorBaseType, True)
End Function 'ICustomTypeDescriptor.GetEditor
Overloads Function GetEvents() As EventDescriptorCollection Implements ICustomTypeDescriptor.GetEvents
Return TypeDescriptor.GetEvents(Me, True)
End Function 'ICustomTypeDescriptor.GetEvents
Overloads Function GetEvents(ByVal attributes() As Attribute) As EventDescriptorCollection Implements ICustomTypeDescriptor.GetEvents
Return TypeDescriptor.GetEvents(Me, attributes, True)
End Function 'ICustomTypeDescriptor.GetEvents
Overloads Function GetProperties() As PropertyDescriptorCollection Implements ICustomTypeDescriptor.GetProperties
Return CType(Me, ICustomTypeDescriptor).GetProperties(New Attribute(0) {})
End Function 'ICustomTypeDescriptor.GetProperties
Overloads Function GetProperties(ByVal attributes() As Attribute) As PropertyDescriptorCollection Implements ICustomTypeDescriptor.GetProperties
' Rather than passing this function on to the default TypeDescriptor,
' which would return the actual properties of PropertyBag, I construct
' a list here that contains property descriptors for the elements of the
' Properties list in the bag.
Dim props As New ArrayList
Dim mproperty As PropertySpec
For Each mproperty In Properties
Dim attrs As New ArrayList
' If a category, description, editor, or type converter are specified
' in the PropertySpec, create attributes to define that relationship.
If Not (mproperty.Category Is Nothing) Then
attrs.Add(New CategoryAttribute(mproperty.Category))
End If
If Not (mproperty.Description Is Nothing) Then
attrs.Add(New DescriptionAttribute(mproperty.Description))
End If
If Not (mproperty.EditorTypeName Is Nothing) Then
attrs.Add(New EditorAttribute(mproperty.EditorTypeName, GetType(UITypeEditor)))
End If
If Not (mproperty.ConverterTypeName Is Nothing) Then
attrs.Add(New TypeConverterAttribute(mproperty.ConverterTypeName))
End If
' Additionally, append the custom attributes associated with the
' PropertySpec, if any.
If Not (mproperty.Attributes Is Nothing) Then
attrs.AddRange(mproperty.Attributes)
End If
Dim attrArray As Attribute() = CType(attrs.ToArray(GetType(Attribute)), Attribute())
' Create a new property descriptor for the property item, and add
' it to the list.
Dim pd As New PropertySpecDescriptor(mproperty, Me, mproperty.Name, attrArray)
props.Add(pd)
Next mproperty
' Convert the list of PropertyDescriptors to a collection that the
' ICustomTypeDescriptor can use, and return it.
Dim propArray As PropertyDescriptor() = CType(props.ToArray(GetType(PropertyDescriptor)), PropertyDescriptor())
Return New PropertyDescriptorCollection(propArray)
End Function 'ICustomTypeDescriptor.GetProperties
Function GetPropertyOwner(ByVal pd As PropertyDescriptor) As Object Implements ICustomTypeDescriptor.GetPropertyOwner
Return Me
End Function 'ICustomTypeDescriptor.GetPropertyOwner
End Class 'PropertyBag
'_ '
'ToDo: Error processing original source shown below
'
'
'-----^--- Pre-processor directives not translated
'
'ToDo: Error processing original source shown below
'
'
'--^--- Unexpected pre-processor directive
'/
'/ An extension of PropertyBag that manages a table of property values, in
'/ addition to firing events when property values are requested or set.
'/
Public Class PropertyTable
Inherits PropertyBag
Private propValues As Hashtable
'/
'/ Initializes a new instance of the PropertyTable class.
'/
Public Sub New()
propValues = New Hashtable
End Sub 'New
'/
'/ Gets or sets the value of the property with the specified name.
'/ In C#, this property is the indexer of the PropertyTable class.
'/
Default Public Property Item(ByVal key As String) As Object
Get
Return propValues(key)
End Get
Set(ByVal Value As Object)
propValues(key) = Value
End Set
End Property
'/
'/ This member overrides PropertyBag.OnGetValue.
'/
Protected Overrides Sub OnGetValue(ByVal e As PropertySpecEventArgs)
e.Value = propValues(e.Property.Name)
MyBase.OnGetValue(e)
End Sub 'OnGetValue
'/
'/ This member overrides PropertyBag.OnSetValue.
'/
Protected Overrides Sub OnSetValue(ByVal e As PropertySpecEventArgs)
propValues(e.Property.Name) = e.Value
MyBase.OnSetValue(e)
End Sub 'OnSetValue
End Class 'PropertyTable
'
|
|
|
|
|
Can you provide a sample code showing how to instantiate the vb.net version please ?
|
|
|
|
|
The sample code will be something like this:
_______________________________________
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Public Class PropBagTestForm
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
' Create the first property bag and add some properties.
bag1 = New PropertyBag
AddHandler bag1.GetValue, AddressOf Me.bag1_GetValue
AddHandler bag1.SetValue, AddressOf Me.bag1_SetValue
bag1.Properties.Add(New PropertySpec("Fruit", GetType(Fruit), Nothing, Nothing, Fruit.Orange))
bag1.Properties.Add(New PropertySpec("Picture", GetType(Image), "Some Category", "This is a sample description."))
Dim item1 As New ListViewItem("Bag 1", 0)
item1.Tag = bag1
listView.Items.Add(item1)
' Create the second property bag and add some properties.
bag2 = New PropertyBag
AddHandler bag2.GetValue, AddressOf Me.bag2_GetValue
AddHandler bag2.SetValue, AddressOf Me.bag2_SetValue
bag2.Properties.Add(New PropertySpec("Fruit", GetType(Fruit), Nothing, Nothing, Fruit.Banana))
bag2.Properties.Add(New PropertySpec("Typeface", GetType(Font), "Another Category", Nothing, New Font("Tahoma", 8.25F)))
bag2.Properties.Add(New PropertySpec("Some Boolean", "System.Boolean", "Some Category", Nothing, False))
Dim item2 As New ListViewItem("Bag 2", 0)
item2.Tag = bag2
listView.Items.Add(item2)
' This time, create a property table. It uses a Hashtable to store
' values, so we don't need to wire GetValue and SetValue events.
bag3 = New PropertyTable
bag3.Properties.Add(New PropertySpec("Fruit", GetType(Fruit), Nothing, Nothing, Fruit.Orange))
bag3.Properties.Add(New PropertySpec("Picture", GetType(Image), "Some Category", "This is a sample description."))
bag3.Properties.Add(New PropertySpec("Typeface", GetType(Font), "Another Category", Nothing, New Font("Tahoma", 8.25F)))
bag3.Properties.Add(New PropertySpec("Some Boolean", "System.Boolean", "Some Category", Nothing, False))
bag3.Properties.Add(New PropertySpec("Number", "System.Int64", Nothing, "A big number.", 1234567890L))
' Create a property that uses additional attributes.
Dim ps As New PropertySpec("Can't Touch This", GetType(String), Nothing, "This property is read-only.", "Some Default String")
ps.Attributes = New Attribute() {ReadOnlyAttribute.Yes}
bag3.Properties.Add(ps)
' Assign values to the properties above.
bag3("Fruit") = Fruit.Apple
bag3("Picture") = Nothing
bag3("Typeface") = New Font("Times New Roman", 12.0F)
bag3("Some Boolean") = True
bag3("Number") = 1234567890L
bag3("Can't Touch This") = "Some Default String"
Dim item3 As New ListViewItem("Table", 0)
item3.Tag = bag3
listView.Items.Add(item3)
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents imageList As System.Windows.Forms.ImageList
Friend WithEvents menuReset As System.Windows.Forms.MenuItem
Friend WithEvents label1 As System.Windows.Forms.Label
Friend WithEvents propertyGrid As System.Windows.Forms.PropertyGrid
Friend WithEvents listView As System.Windows.Forms.ListView
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(PropBagTestForm))
Me.imageList = New System.Windows.Forms.ImageList(Me.components)
Me.menuReset = New System.Windows.Forms.MenuItem
Me.label1 = New System.Windows.Forms.Label
Me.contextMenu = New System.Windows.Forms.ContextMenu
Me.propertyGrid = New System.Windows.Forms.PropertyGrid
Me.listView = New System.Windows.Forms.ListView
Me.SuspendLayout()
'
'imageList
'
Me.imageList.ImageSize = New System.Drawing.Size(32, 32)
Me.imageList.ImageStream = CType(resources.GetObject("imageList.ImageStream"), System.Windows.Forms.ImageListStreamer)
Me.imageList.TransparentColor = System.Drawing.Color.Transparent
'
'menuReset
'
Me.menuReset.Index = 0
Me.menuReset.Text = "Reset"
'
'label1
'
Me.label1.Location = New System.Drawing.Point(8, 8)
Me.label1.Name = "label1"
Me.label1.Size = New System.Drawing.Size(448, 23)
Me.label1.TabIndex = 5
Me.label1.Text = "Select one or multiple items in the list to see those objects in the property gri" & _
"d."
'
'contextMenu
'
Me.contextMenu.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.menuReset})
'
'propertyGrid
'
Me.propertyGrid.CommandsVisibleIfAvailable = True
Me.propertyGrid.ContextMenu = Me.contextMenu
Me.propertyGrid.LargeButtons = False
Me.propertyGrid.LineColor = System.Drawing.SystemColors.ScrollBar
Me.propertyGrid.Location = New System.Drawing.Point(176, 32)
Me.propertyGrid.Name = "propertyGrid"
Me.propertyGrid.Size = New System.Drawing.Size(272, 264)
Me.propertyGrid.TabIndex = 4
Me.propertyGrid.Text = "propertyGrid1"
Me.propertyGrid.ViewBackColor = System.Drawing.SystemColors.Window
Me.propertyGrid.ViewForeColor = System.Drawing.SystemColors.WindowText
'
'listView
'
Me.listView.HideSelection = False
Me.listView.LargeImageList = Me.imageList
Me.listView.Location = New System.Drawing.Point(0, 32)
Me.listView.Name = "listView"
Me.listView.Size = New System.Drawing.Size(168, 264)
Me.listView.TabIndex = 3
'
'PropBagTestForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(448, 301)
Me.Controls.Add(Me.listView)
Me.Controls.Add(Me.label1)
Me.Controls.Add(Me.propertyGrid)
Me.Name = "PropBagTestForm"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private bag1 As PropertyBag
Private bag2 As PropertyBag
Private bag3 As PropertyTable
' A simple enumerated type used in the property bags.
Private Enum Fruit
Apple
Banana
Orange
Peach
Pear
End Enum 'Fruit
Private Sub listView_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles listView.SelectedIndexChanged
Dim objs As New ArrayList
Dim item As ListViewItem
For Each item In listView.SelectedItems
objs.Add(item.Tag)
Next item
propertyGrid.SelectedObjects = objs.ToArray()
End Sub 'listView_SelectedIndexChanged
Private Sub menuReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles menuReset.Click
If Not (propertyGrid.SelectedObject Is Nothing) And Not (propertyGrid.SelectedGridItem Is Nothing) Then
propertyGrid.ResetSelectedProperty()
End If
End Sub 'menuReset_Click
' Member variables associated with the properties of bag 1 and
' bag 2. Since events are fired to query these, you could use
' any source--variables, contents of a file, a database, etc.
Private bag1_Fruit As Fruit = Fruit.Orange
Private bag1_Picture As Image = Nothing
Private bag2_Fruit As Fruit = Fruit.Banana
Private bag2_Typeface As New Font("Tahoma", 8.25F)
Private bag2_SomeBoolean As Boolean = False
' This is a pretty basic way to handle the properties. Optimally,
' you might have some kind of table that indexes into a database
' or file where the values are stored. But for the purposes of this
' example, a simple case statement will do.
Private Sub bag1_GetValue(ByVal sender As Object, ByVal e As PropertySpecEventArgs)
Select Case e.Property.Name
Case "Fruit"
e.Value = bag1_Fruit
Case "Picture"
e.Value = bag1_Picture
End Select
End Sub 'bag1_GetValue
Private Sub bag1_SetValue(ByVal sender As Object, ByVal e As PropertySpecEventArgs)
Select Case e.Property.Name
Case "Fruit"
bag1_Fruit = CType(e.Value, Fruit)
Case "Picture"
bag1_Picture = CType(e.Value, Image)
End Select
End Sub 'bag1_SetValue
Private Sub bag2_GetValue(ByVal sender As Object, ByVal e As PropertySpecEventArgs)
Select Case e.Property.Name
Case "Fruit"
e.Value = bag2_Fruit
Case "Typeface"
e.Value = bag2_Typeface
Case "Some Boolean"
e.Value = bag2_SomeBoolean
End Select
End Sub 'bag2_GetValue
Private Sub bag2_SetValue(ByVal sender As Object, ByVal e As PropertySpecEventArgs)
Select Case e.Property.Name
Case "Fruit"
bag2_Fruit = CType(e.Value, Fruit)
Case "Typeface"
bag2_Typeface = CType(e.Value, Font)
Case "Some Boolean"
bag2_SomeBoolean = CBool(e.Value)
End Select
End Sub 'bag2_SetValue
End Class
_______________________________________
|
|
|
|
|
Any one know how i can make one of the input lines in the propertygrid a multiline textbox? Not just a regular textbox?
Please help
|
|
|
|
|
You can write your own type editor or use a string array for the value type
|
|
|
|
|
I've found this a useful addition to the PropertySpecCollection class:
public PropertySpecCollection GetCategory(String CategoryName)
{
PropertySpecCollection psc = new PropertySpecCollection();
foreach (PropertySpec p in innerArray)
{
if (p.Category.Equals(CategoryName))
{
psc.Add(p);
}
}
return psc;
}
|
|
|
|
|
Could you provide an example of using an expandable type converter (one that doesn't need a custom editor)?
Thanks
Kelly
|
|
|
|
|
Nevermind - got it to work. Added my own constructor to PropertyTable for setting the TypeConverter (and not a type editor). Then had to set the value via Properties["myprop"] = mytypeinstance
Kelly
|
|
|
|
|
Can you please post your code for TypeConverter? I am having a trouble with it. I don't know what is wrong.
Thanks.
Naqsh
|
|
|
|
|
Hi
I am using Property Grid to display the properties of My class.
For a particular property, i want the user to select a value from a drop-down list.
How to do that.
Kinldy help me on this.
Thanks and Regards
Karuppasamy Natarajan
|
|
|
|
|
Inherit from a type converter class and override the GetStandardValues method. Then use this type converter class when constructing a PropertySpec object:
class ValueConverter : StringConverter
{
public bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
public StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
PropertySpecDescriptor ps = context.PropertyDescriptor;
return new StandardValuesCollection(ps.ValueList);
// my implementation of ValueList calls the database for a list of values and
// returns a string array of those values to display.
}
public bool GetStandardValuesExlusive(ITypeDescriptorContext context)
{
//Return true for a drop-down list; return false for a drop-down combo box.
return true;
}
}
-RR
|
|
|
|
|
I did something very similar. However, I'm interested in part of your code, specifically this code:
public StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)<br />
{<br />
PropertySpecDescriptor ps = context.PropertyDescriptor;<br />
return new StandardValuesCollection(ps.ValueList);<br />
<br />
}
How did you get a reference to the PropertySpecDescription type? Did you modify the PropertyBag class? I've been looking for an efficient way of passing information to the inherited TypeConverter class (so I can create the list).
--- Thanks, Jeff
|
|
|
|
|
I simply took the PropertySpecDescriptor class definition out of the PropertyBag class, allowing the other classes in the namespace to reference it.
-RR
-RR
|
|
|
|
|