Default Public Property Item(ByVal index As Integer) As BaseColumn
Get
Try
Return CType(List(index), BaseColumn)
Catch ex As Exception
Return Nothing
End Try
End Get
Set(ByVal Value As BaseColumn)
List(index) = Value
End Set
End Property
Public Function Add(ByVal value As BaseColumn) As Integer
Return List.Add(value)
value.Collection = Me
End Function 'Add
Public Sub AddRange(ByVal Items() As BaseColumn)
Dim Item As Object
For Each Item In Items
CType(Item, BaseColumn).Collection = Me
list.Add(Item)
Next
End Sub
Public Function IndexOf(ByVal value As BaseColumn) As Integer
Return List.IndexOf(value)
End Function 'IndexOf
Public Sub Insert(ByVal index As Integer, ByVal value As BaseColumn)
List.Insert(index, value)
End Sub 'Insert
Public Sub Remove(ByVal value As BaseColumn)
List.Remove(value)
End Sub 'Remove
Public Function Contains(ByVal value As BaseColumn) As Boolean
' If value is not of type BaseColumn, this will return false.
Return List.Contains(value)
End Function 'Contains
Protected Shadows Sub OnInsert(ByVal index As Integer, ByVal value As
BaseColumn)
' Insert additional code to be run only when inserting values.
End Sub 'OnInsert
Protected Shadows Sub OnRemove(ByVal index As Integer, ByVal value As
BaseColumn)
' Insert additional code to be run only when removing values.
End Sub 'OnRemove
Protected Shadows Sub OnSet(ByVal index As Integer, ByVal oldValue As
BaseColumn, ByVal newValue As BaseColumn)
' Insert additional code to be run only when setting values.
End Sub 'OnSet
Protected Shadows Sub OnValidate(ByVal value As BaseColumn)
'If Not value.GetType() Is Type.GetType("BaseColumn") Then
'Throw New ArgumentException("value must be of type BaseColumn.",
"value")
'End If
End Sub 'OnValidate
Friend Sub RaisePropertyChangedEvent()
RaiseEvent PropertyChaged()
End Sub
Friend Class ColumnsTypeConverter
Inherits ExpandableObjectConverter
Public Overloads Overrides Function ConvertTo(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal culture As
System.Globalization.CultureInfo, ByVal value As Object, ByVal
destinationType As System.Type) As Object
Return String.Format("Collection")
End Function
Public Overloads Function CanConvertFrom(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal sourceType As
System.Type) As Boolean
If (sourceType Is GetType(String)) Then
Return True
End If
Return MyBase.CanConvertFrom(context, sourceType)
End Function
End Class
End Class
#Region " ColumnCollectionEditor"
Friend Class ColumnCollectionEditor
Inherits System.ComponentModel.Design.CollectionEditor
Private Types() As System.Type
Private cf As CollectionForm
Sub New(ByVal type As System.Type)
MyBase.New(type)
Types = New System.Type() {GetType(BaseColumn), GetType(TextColumn),
GetType(CheckColumn)}
End Sub
Protected Overrides Function CreateNewItemTypes() As System.Type()
Return Types
End Function
Protected Overrides Function CreateCollectionForm() As
System.ComponentModel.Design.CollectionEditor.CollectionForm
Me.cf = MyBase.CreateCollectionForm
Return Me.cf
End Function
Protected Overloads Overrides Function CreateInstance(ByVal itemType As
System.Type) As Object
Dim blahblah As BaseColumn = DirectCast(MyBase.CreateInstance(itemType),
BaseColumn)
If Not Me.Context.Instance Is Nothing Then
End If
Return blahblah
End Function
End Class
#End Region
#Region " Columns Types"
<Serializable(), TypeConverter(GetType(BaseColumn.BaseColumnConverter))> _
Public Class BaseColumn
Inherits Component
Public Enum ColumnTypes
Base = 1
Text = 2
Bool = 3
End Enum
#Region " Declarations "
Protected m_Alignment As System.Windows.Forms.HorizontalAlignment
Protected m_HeaderText As String
Protected m_MappingName As String
Protected m_NullText As String
Protected m_ReadOnly As Boolean
Protected m_Width As Integer
Protected m_Visible As Boolean
Protected m_Collection As Columns
Protected m_ColumnType As ColumnTypes
#End Region
#Region " Properties"
<Description("Gets or sets the alignment of text in a column."), _
Category("General"), _
DefaultValue(System.Windows.Forms.HorizontalAlignment.Left)> _
Public Property Alignment() As System.Windows.Forms.HorizontalAlignment
Get
Return m_Alignment
End Get
Set(ByVal Value As System.Windows.Forms.HorizontalAlignment)
m_Alignment = Value
End Set
End Property
<Description("Gets or sets the text of the column header."), _
Category("General"), _
DefaultValue("")> _
Public Property HeaderText() As String
Get
Return m_HeaderText
End Get
Set(ByVal Value As String)
m_HeaderText = Value
End Set
End Property
<Description("Gets or sets the name used to map the column style to a data
member."), _
Category("General"), _
DefaultValue("")> _
Public Property MappingName() As String
Get
Return m_MappingName
End Get
Set(ByVal Value As String)
m_MappingName = Value
End Set
End Property
<Description("Gets or sets the text that is displayed when the column
contains a null reference (Nothing in Visual Basic)."), _
Category("General"), _
DefaultValue("")> _
Public Property NullText() As String
Get
Return m_NullText
End Get
Set(ByVal Value As String)
m_NullText = Value
End Set
End Property
<Description("Gets or sets a value indicating whether the data in the
column can be edited."), _
Category("General"), _
DefaultValue(True)> _
Public Property [ReadOnly]() As Boolean
Get
Return m_ReadOnly
End Get
Set(ByVal Value As Boolean)
m_ReadOnly = Value
End Set
End Property
<Description("Gets or sets the width of the column."), _
Category("General"), _
DefaultValue(50)> _
Public Property Width() As Integer
Get
Return m_Width
End Get
Set(ByVal Value As Integer)
m_Width = Value
End Set
End Property
<Description("Gets or sets weather the column should be displayed in the
datagrid."), _
Category("General"), _
DefaultValue(True)> _
Public Property Visible() As Boolean
Get
Return m_Visible
End Get
Set(ByVal Value As Boolean)
m_Visible = Value
End Set
End Property
Public WriteOnly Property Collection() As Columns
Set(ByVal Value As Columns)
m_Collection = Value
End Set
End Property
<Browsable(True)> Public ReadOnly Property ColumnType() As ColumnTypes
Get
Return ColumnTypes.Base
End Get
End Property
#End Region
#Region " Methods"
Protected Sub PropertyChanged()
'Check if the collection is a valid object if not during design time you
and up with a message 'Object is not set to an Instance' But Your Program
Works
'By the way I am looking forward for the IsNot operator in VS 2005,
because every time I forget the Not Operator and need to navigate back
If Not m_Collection Is Nothing Then
m_Collection.RaisePropertyChangedEvent()
End If
End Sub
Public Overrides Function ToString() As String
Return m_MappingName
End Function
#End Region
Friend Class BaseColumnConverter
Inherits ExpandableObjectConverter
Public Overloads Overrides Function ConvertTo(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal culture As
System.Globalization.CultureInfo, ByVal value As Object, ByVal
destinationType As System.Type) As Object
Dim mi As BaseColumn = CType(value, BaseColumn)
Return String.Format("{0}", mi.MappingName)
End Function
Public Overloads Function CanConvertFrom(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal sourceType As
System.Type) As Boolean
If (sourceType Is GetType(String)) Then
Return True
End If
Return MyBase.CanConvertFrom(context, sourceType)
End Function
End Class
End Class
<Serializable(), TypeConverter(GetType(TextColumn.TextColumnConverter))> _
Public Class TextColumn
Inherits BaseColumn
Private m_Format As String
<Description("Gets or sets the character(s) that specify how text is
formatted."), _
Category("General"), _
DefaultValue("")> _
Public Property Format() As String
Get
Return m_Format
End Get
Set(ByVal Value As String)
m_Format = Value
End Set
End Property
<Browsable(True)> Public Shadows ReadOnly Property ColumnType() As
ColumnTypes
Get
Return ColumnTypes.Text
End Get
End Property
Friend Class TextColumnConverter
Inherits BaseColumn.BaseColumnConverter
Public Overloads Overrides Function ConvertTo(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal culture As
System.Globalization.CultureInfo, ByVal value As Object, ByVal
destinationType As System.Type) As Object
Dim mi As TextColumn = CType(value, TextColumn)
Return String.Format("{0}", mi.MappingName)
End Function
End Class
End Class
<Serializable(), TypeConverter(GetType(CheckColumn.CheckColumnConverter))> _
Public Class CheckColumn
Inherits BaseColumn
Protected m_TrueValue As Object
Protected m_FalseValue As Object
<Description("Gets or sets the actual value used when setting the value of
the column to true."), _
Category("General"), _
DefaultValue(False)> _
Public Property TrueValue() As String
Get
Return CType(m_TrueValue, String)
End Get
Set(ByVal Value As String)
m_TrueValue = Value
End Set
End Property
<Description("Gets or sets the actual value used when setting the value of
the column to false."), _
Category("General"), _
DefaultValue(False)> _
Public Property FalseValue() As String
Get
Return CType(m_FalseValue, String)
End Get
Set(ByVal Value As String)
m_FalseValue = Value
End Set
End Property
<Browsable(True)> Public Shadows ReadOnly Property ColumnType() As
ColumnTypes
Get
Return ColumnTypes.Bool
End Get
End Property
Friend Class CheckColumnConverter
Inherits BaseColumn.BaseColumnConverter
Public Overloads Overrides Function ConvertTo(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal culture As
System.Globalization.CultureInfo, ByVal value As Object, ByVal
destinationType As System.Type) As Object
Dim mi As CheckColumn = CType(value, CheckColumn)
Return String.Format("{0}", mi.MappingName)
End Function
End Class
End Class
#End Region
#End Region
Michael said:
Dear all ..
If I want to use develop a user control and declare a public property
which the type is System.Windows.Forms.GridTableStylesCollection
For example :
Public Class LookAndView
Inherits System.Windows.Forms.UserControl
Private _Collection As GridTableStylesCollection
Public Property Styles() As
System.Windows.Forms.GridTableStylesCollection
Get
Return _Collection
End Get
Set(ByVal Value As System.Windows.Forms.GridTableStylesCollection)
_Collection = Value
End Set
End Property
emd class
I want the properties Styles can edit in style collection editor during
in design mode. However, I find there some problem :
1. Styles property show empty / nothing (I know the normal case is show
collection)
2. When I click new in style collection editor and input some value into
properites. And then I click ok. During open the style collection editor.
the member side still nothing.
Can any one help me to solve this problem ?
Thanks for your help
Michael VB developer