473,695 Members | 2,767 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

User style collection editor for GridTableStyles Collection

Dear all ..

If I want to use develop a user control and declare a public property which
the type is System.Windows. Forms.GridTable StylesCollectio n

For example :

Public Class LookAndView
Inherits System.Windows. Forms.UserContr ol
Private _Collection As GridTableStyles Collection
Public Property Styles() As
System.Windows. Forms.GridTable StylesCollectio n
Get
Return _Collection
End Get
Set(ByVal Value As System.Windows. Forms.GridTable StylesCollectio n)
_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
Nov 21 '05 #1
4 2516
I am working a very similar project and am running into an issue getting the
values to save during design time. Perhaps we can share notes?

If anyone else has any ideas where I am going wrong, please let me know.
Thanks.

Here is what I have:

<Serializable() , _
ToolboxItem(Tru e), _
TypeConverter(G etType(Datatabl eManager.Datata bleManagerTypeC onverter))> _
Public Class DatatableManage r
Inherits System.Componen tModel.Componen t

#Region " Declarations"
Private m_AllowSorting As Boolean = False
Private m_AlternatingBa ckColor As Color = System.Drawing. Color.White
Private m_BackColor As Color = System.Drawing. Color.White
Private m_ColumnHeaders Visible As Boolean = True
Private m_ForeColor As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.WindowText)
Private m_GridLineColor As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.Control)
Private m_GridLineStyle As DataGridLineSty le
Private m_HeaderBackCol or As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.Control)
Private m_HeaderFont As Font = New Font("Microsoft Sans Serif", 8.25)
Private m_HeaderForeCol or As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.ControlText)
Private m_LinkColor As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.HotTrack)
Private m_MappingName As String = ""
Private m_PreferredColu mnWidth As Integer = 75
Private m_PreferredRowH eight As Integer = 16
Private m_ReadOnly As Boolean = False
Private m_RowHeadersVis ible As Boolean = True
Private m_RowHeaderWidt h As Integer = 35
Private m_SelectionBack Color As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.ActiveCaption )
Private m_SelectionFore Color As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.ActiveCaption Text)
Private m_Columns As Columns
#End Region

#Region " Component Designer generated code "

Public Sub New(ByVal Container As System.Componen tModel.IContain er)
MyClass.New()

'Required for Windows.Forms Class Composition Designer support
Container.Add(M e)
m_Columns = New Columns
End Sub

Public Sub New()
MyBase.New()

'This call is required by the Component Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call
End Sub

'Component 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.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Component Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
components = New System.Componen tModel.Containe r
End Sub

#End Region

#Region " Properties"

<Description("I ndicates whether sorting is allowed on the grid table when
this DataGridTableSt yle is used."), _
Category("Usabi lity")> _
Public Property AllowSorting() As Boolean
Get
Return m_AllowSorting
End Get
Set(ByVal Value As Boolean)
m_AllowSorting = Value
End Set
End Property
<Description("G ets or sets the background color of odd-numbered rows of
the grid."), _
Category("Appea rance")> _
Public Property AlternatingBack Color() As Color
Get
Return m_AlternatingBa ckColor
End Get
Set(ByVal Value As Color)
m_AlternatingBa ckColor = Value
End Set
End Property
<Description("G ets or sets the background color of even-numbered rows of
the grid."), _
Category("Appea rance")> _
Public Property BackColor() As Color
Get
Return m_BackColor
End Get
Set(ByVal Value As Color)
m_BackColor = Value
End Set
End Property
<Description("G ets or sets a value indicating whether column headers are
visible."), _
Category("Appea rance")> _
Public Property ColumnHeadersVi sible() As Boolean
Get
Return m_ColumnHeaders Visible
End Get
Set(ByVal Value As Boolean)
m_ColumnHeaders Visible = Value
End Set
End Property
<Description("G ets or sets the foreground color of the grid table."), _
Category("Appea rance"), _
DefaultValue(Tr ue)> _
Public Property ForeColor() As Color
Get
Return m_ForeColor
End Get
Set(ByVal Value As Color)
m_ForeColor = Value
End Set
End Property
<Description("G ets or sets the color of grid lines."), _
Category("Appea rance")> _
Public Property GridLineColor() As Color
Get
Return m_GridLineColor
End Get
Set(ByVal Value As Color)
m_GridLineColor = Value
End Set
End Property
<Description("G ets or sets the style of grid lines."), _
Category("Appea rance")> _
Public Property GridLineStyle() As DataGridLineSty le
Get
Return m_GridLineStyle
End Get
Set(ByVal Value As DataGridLineSty le)
m_GridLineStyle = Value
End Set
End Property
<Description("G ets or sets the background color of headers."), _
Category("Appea rance")> _
Public Property HeaderBackColor () As Color
Get
Return m_HeaderBackCol or
End Get
Set(ByVal Value As Color)
m_HeaderBackCol or = Value
End Set
End Property
<Description("G ets or sets the font used for header captions."), _
Category("Appea rance")> _
Public Property HeaderFont() As Font
Get
Return m_HeaderFont
End Get
Set(ByVal Value As Font)
m_HeaderFont = Value
End Set
End Property
<Description("G ets or sets the foreground color of headers."), _
Category("Appea rance")> _
Public Property HeaderForeColor () As Color
Get
Return m_HeaderForeCol or
End Get
Set(ByVal Value As Color)
m_HeaderForeCol or = Value
End Set
End Property
<Description("G ets or sets the color of link text."), _
Category("Appea rance")> _
Public Property LinkColor() As Color
Get
Return m_LinkColor
End Get
Set(ByVal Value As Color)
m_LinkColor = Value
End Set
End Property
<Description("G ets or sets the name used to map this table to a specific
data source."), _
Category("Gener al")> _
Public Property MappingName() As String
Get
Return m_MappingName
End Get
Set(ByVal Value As String)
m_MappingName = Value
End Set
End Property
<Description("G ets or sets the width used to create columns when a new
grid is displayed."), _
Category("Gener al")> _
Public Property PreferredColumn Width() As Integer
Get
Return m_PreferredColu mnWidth
End Get
Set(ByVal Value As Integer)
m_PreferredColu mnWidth = Value
End Set
End Property
<Description("G ets or sets the height used to create a row when a new grid
is displayed."), _
Category("Appea rance")> _
Public Property PreferredRowHei ght() As Integer
Get
Return m_PreferredRowH eight
End Get
Set(ByVal Value As Integer)
m_PreferredRowH eight = Value
End Set
End Property
<Description("G ets or sets a value indicating whether columns can be
edited."), _
Category("Usabi lity")> _
Public Property [ReadOnly]() As Boolean
Get
Return m_ReadOnly
End Get
Set(ByVal Value As Boolean)
m_ReadOnly = Value
End Set
End Property
<Description("G ets or sets a value indicating whether row headers are
visible."), _
Category("Appea rance")> _
Public Property RowHeadersVisib le() As Boolean
Get
Return m_RowHeadersVis ible
End Get
Set(ByVal Value As Boolean)
m_RowHeadersVis ible = Value
End Set
End Property
<Description("G ets or sets the width of row headers."), _
Category("Appea rance")> _
Public Property RowHeaderWidth( ) As Integer
Get
Return m_RowHeaderWidt h
End Get
Set(ByVal Value As Integer)
m_RowHeaderWidt h = Value
End Set
End Property
<Description("G ets or sets the background color of selected cells."), _
Category("Appea rance")> _
Public Property SelectionBackCo lor() As Color
Get
Return m_SelectionBack Color
End Get
Set(ByVal Value As Color)
m_SelectionBack Color = Value
End Set
End Property
<Description("G ets or sets the foreground color of selected cells."), _
Category("Appea rance")> _
Public Property SelectionForeCo lor() As Color
Get
Return m_SelectionFore Color
End Get
Set(ByVal Value As Color)
m_SelectionFore Color = Value
End Set
End Property
<Description("G ets or sets the collection of columns available for display
in the datagrid."), _
Category("Data" ), _
DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Content),
_
Editor(GetType( ColumnCollectio nEditor), GetType(UITypeE ditor))> _
Public Property Columns() As Columns
Get
Return m_Columns
End Get
Set(ByVal Value As Columns)
m_Columns = Value
End Set
End Property

#End Region

Friend Class DatatableManage rTypeConverter
Inherits ExpandableObjec tConverter

Public Overloads Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, ByVal value As Object, ByVal
destinationType As System.Type) As Object
Return String.Format(" Data table manager")
End Function

Public Overloads Function CanConvertFrom( ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal sourceType As
System.Type) As Boolean

If (sourceType Is GetType(String) ) Then
Return True
End If

Return MyBase.CanConve rtFrom(context, sourceType)

End Function
End Class

Friend Class DatatableManage rDesigner
Inherits System.Windows. Forms.Design.Co ntrolDesigner

Private MyControl As DatatableManage r

Public Overrides Sub Initialize(ByVa l component As IComponent)

Try
MyBase.Initiali ze(component)

'// Record instance of control we're designing
MyControl = DirectCast(comp onent, DatatableManage r)

'// Hook up events
Dim s As ISelectionServi ce =
DirectCast(GetS ervice(GetType( ISelectionServi ce)), ISelectionServi ce)
Dim c As IComponentChang eService =
DirectCast(GetS ervice(GetType( IComponentChang eService)),
IComponentChang eService)
AddHandler s.SelectionChan ged, New EventHandler(Ad dressOf
OnSelectionChan ged)
AddHandler c.ComponentRemo ving, New ComponentEventH andler(AddressO f
OnComponentRemo ving)
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try
End Sub

Private Sub OnSelectionChan ged(ByVal sender As Object, ByVal e As
System.EventArg s)

'MyControl.OnSe lectionChanged( )

End Sub

Private Sub OnComponentRemo ving(ByVal sender As Object, ByVal e As
ComponentEventA rgs)

Try
Dim c As IComponentChang eService =
DirectCast(GetS ervice(GetType( IComponentChang eService)),
IComponentChang eService)
Dim bc As BaseColumn
Dim h As IDesignerHost =
DirectCast(GetS ervice(GetType( IDesignerHost)) , IDesignerHost)

'// If the user is removing a button
If (TypeOf e.Component Is BaseColumn) Then

bc = DirectCast(e.Co mponent, BaseColumn)
If (MyControl.Colu mns.Contains(bc )) Then

c.OnComponentCh anging(MyContro l, Nothing)
MyControl.Colum ns.Remove(bc)
c.OnComponentCh anged(MyControl , Nothing, Nothing, Nothing)
Return
End If
End If

'// If the user is removing the control itself
If (e.Component Is MyControl) Then

For i As Int32 = MyControl.Colum ns.Count - 1 To 0 Step -1

bc = MyControl.Colum ns(i)
c.OnComponentCh anging(MyContro l, Nothing)
MyControl.Colum ns.Remove(bc)
h.DestroyCompon ent(bc)
c.OnComponentCh anged(MyControl , Nothing, Nothing, Nothing)
Next i

End If
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try
End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

Try
Dim s As ISelectionServi ce =
DirectCast(GetS ervice(GetType( ISelectionServi ce)), ISelectionServi ce)
Dim c As IComponentChang eService =
DirectCast(GetS ervice(GetType( IComponentChang eService)),
IComponentChang eService)

'// Unhook events
RemoveHandler s.SelectionChan ged, New EventHandler(Ad dressOf
OnSelectionChan ged)
RemoveHandler c.ComponentRemo ving, New
ComponentEventH andler(AddressO f OnComponentRemo ving)
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try

MyBase.Dispose( disposing)

End Sub

Public Overrides ReadOnly Property AssociatedCompo nents() As
System.Collecti ons.ICollection
Get

Try
Return MyControl.Colum ns
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try

End Get
End Property

Public Overrides ReadOnly Property Verbs() As
System.Componen tModel.Design.D esignerVerbColl ection

Get

Try
Dim v As DesignerVerbCol lection = New DesignerVerbCol lection

'// Verb to add buttons
v.Add(New DesignerVerb("& Add Column", New EventHandler(Ad dressOf
OnAddButton)))

Return v
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try

End Get

End Property

Private Sub OnAddButton(ByV al sender As Object, ByVal e As
System.EventArg s)

Try
Dim bc As BaseColumn
Dim h As IDesignerHost =
DirectCast(GetS ervice(GetType( IDesignerHost)) , IDesignerHost)
Dim dt As DesignerTransac tion
Dim c As IComponentChang eService =
DirectCast(GetS ervice(GetType( IComponentChang eService)),
IComponentChang eService)

'// Add a new button to the collection
dt = h.CreateTransac tion("Add Column")
bc = DirectCast(h.Cr eateComponent(G etType(BaseColu mn)), BaseColumn)
c.OnComponentCh anging(MyContro l, Nothing)
MyControl.Colum ns.Add(bc)
c.OnComponentCh anged(MyControl , Nothing, Nothing, Nothing)
dt.Commit()
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try

End Sub

End Class
End Class

#Region " Column Collection "

'<TypeConverter (GetType(Column s.ColumnsTypeCo nverter))>

Public Class Columns
Inherits CollectionBase

Event PropertyChaged( )

'<DesignerSeria lizationVisibil ity(DesignerSer ializationVisib ility.Content)>

Default Public Property Item(ByVal index As Integer) As BaseColumn
Get
Try
Return CType(List(inde x), 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.Collectio n = Me
End Function 'Add

Public Sub AddRange(ByVal Items() As BaseColumn)
Dim Item As Object
For Each Item In Items
CType(Item, BaseColumn).Col lection = Me
list.Add(Item)
Next
End Sub

Public Function IndexOf(ByVal value As BaseColumn) As Integer
Return List.IndexOf(va lue)
End Function 'IndexOf

Public Sub Insert(ByVal index As Integer, ByVal value As BaseColumn)
List.Insert(ind ex, value)
End Sub 'Insert

Public Sub Remove(ByVal value As BaseColumn)
List.Remove(val ue)

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(v alue)
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(ByVa l value As BaseColumn)
'If Not value.GetType() Is Type.GetType("B aseColumn") Then
'Throw New ArgumentExcepti on("value must be of type BaseColumn.",
"value")
'End If
End Sub 'OnValidate

Friend Sub RaisePropertyCh angedEvent()
RaiseEvent PropertyChaged( )
End Sub

Friend Class ColumnsTypeConv erter
Inherits ExpandableObjec tConverter

Public Overloads Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, 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.Componen tModel.ITypeDes criptorContext, ByVal sourceType As
System.Type) As Boolean

If (sourceType Is GetType(String) ) Then
Return True
End If

Return MyBase.CanConve rtFrom(context, sourceType)

End Function
End Class

End Class

#Region " ColumnCollectio nEditor"

Friend Class ColumnCollectio nEditor
Inherits System.Componen tModel.Design.C ollectionEditor

Private Types() As System.Type
Private cf As CollectionForm

Sub New(ByVal type As System.Type)
MyBase.New(type )
Types = New System.Type() {GetType(BaseCo lumn), GetType(TextCol umn),
GetType(CheckCo lumn)}
End Sub

Protected Overrides Function CreateNewItemTy pes() As System.Type()
Return Types
End Function

Protected Overrides Function CreateCollectio nForm() As
System.Componen tModel.Design.C ollectionEditor .CollectionForm
Me.cf = MyBase.CreateCo llectionForm
Return Me.cf
End Function

Protected Overloads Overrides Function CreateInstance( ByVal itemType As
System.Type) As Object

Dim blahblah As BaseColumn = DirectCast(MyBa se.CreateInstan ce(itemType),
BaseColumn)

If Not Me.Context.Inst ance Is Nothing Then
End If

Return blahblah

End Function

End Class

#End Region

#Region " Columns Types"

<Serializable() , TypeConverter(G etType(BaseColu mn.BaseColumnCo nverter))> _
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.Horizonta lAlignment
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("G ets or sets the alignment of text in a column."), _
Category("Gener al"), _
DefaultValue(Sy stem.Windows.Fo rms.HorizontalA lignment.Left)> _
Public Property Alignment() As System.Windows. Forms.Horizonta lAlignment
Get
Return m_Alignment
End Get
Set(ByVal Value As System.Windows. Forms.Horizonta lAlignment)
m_Alignment = Value
End Set
End Property

<Description("G ets or sets the text of the column header."), _
Category("Gener al"), _
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("G ets or sets the name used to map the column style to a data
member."), _
Category("Gener al"), _
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("G ets or sets the text that is displayed when the column
contains a null reference (Nothing in Visual Basic)."), _
Category("Gener al"), _
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("G ets or sets a value indicating whether the data in the
column can be edited."), _
Category("Gener al"), _
DefaultValue(Tr ue)> _
Public Property [ReadOnly]() As Boolean
Get
Return m_ReadOnly
End Get
Set(ByVal Value As Boolean)
m_ReadOnly = Value
End Set
End Property

<Description("G ets or sets the width of the column."), _
Category("Gener al"), _
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("G ets or sets weather the column should be displayed in the
datagrid."), _
Category("Gener al"), _
DefaultValue(Tr ue)> _
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.Bas e
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.Ra isePropertyChan gedEvent()
End If
End Sub

Public Overrides Function ToString() As String
Return m_MappingName
End Function

#End Region

Friend Class BaseColumnConve rter
Inherits ExpandableObjec tConverter

Public Overloads Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, 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.Componen tModel.ITypeDes criptorContext, ByVal sourceType As
System.Type) As Boolean

If (sourceType Is GetType(String) ) Then
Return True
End If

Return MyBase.CanConve rtFrom(context, sourceType)

End Function

End Class

End Class

<Serializable() , TypeConverter(G etType(TextColu mn.TextColumnCo nverter))> _
Public Class TextColumn
Inherits BaseColumn

Private m_Format As String

<Description("G ets or sets the character(s) that specify how text is
formatted."), _
Category("Gener al"), _
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.Tex t
End Get
End Property

Friend Class TextColumnConve rter
Inherits BaseColumn.Base ColumnConverter
Public Overloads Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, 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(G etType(CheckCol umn.CheckColumn Converter))> _
Public Class CheckColumn
Inherits BaseColumn

Protected m_TrueValue As Object
Protected m_FalseValue As Object

<Description("G ets or sets the actual value used when setting the value of
the column to true."), _
Category("Gener al"), _
DefaultValue(Fa lse)> _
Public Property TrueValue() As String
Get
Return CType(m_TrueVal ue, String)
End Get
Set(ByVal Value As String)
m_TrueValue = Value
End Set
End Property

<Description("G ets or sets the actual value used when setting the value of
the column to false."), _
Category("Gener al"), _
DefaultValue(Fa lse)> _
Public Property FalseValue() As String
Get
Return CType(m_FalseVa lue, 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.Boo l
End Get
End Property

Friend Class CheckColumnConv erter
Inherits BaseColumn.Base ColumnConverter
Public Overloads Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, 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" <la********@gma il.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Dear all ..

If I want to use develop a user control and declare a public property
which the type is System.Windows. Forms.GridTable StylesCollectio n

For example :

Public Class LookAndView
Inherits System.Windows. Forms.UserContr ol
Private _Collection As GridTableStyles Collection
Public Property Styles() As
System.Windows. Forms.GridTable StylesCollectio n
Get
Return _Collection
End Get
Set(ByVal Value As System.Windows. Forms.GridTable StylesCollectio n)
_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

Nov 21 '05 #2
Thanks AMDRIT ..

Thank for your help .....very much
I get it and solve this problem

Michael

"AMDRIT" <am****@hotmail .com> 秎ン
news:et******** ******@TK2MSFTN GP09.phx.gbl い级糶...
I am working a very similar project and am running into an issue getting the values to save during design time. Perhaps we can share notes?

If anyone else has any ideas where I am going wrong, please let me know.
Thanks.

Here is what I have:

<Serializable() , _
ToolboxItem(Tru e), _
TypeConverter(G etType(Datatabl eManager.Datata bleManagerTypeC onverter))> _ Public Class DatatableManage r
Inherits System.Componen tModel.Componen t

#Region " Declarations"
Private m_AllowSorting As Boolean = False
Private m_AlternatingBa ckColor As Color = System.Drawing. Color.White
Private m_BackColor As Color = System.Drawing. Color.White
Private m_ColumnHeaders Visible As Boolean = True
Private m_ForeColor As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.WindowText)
Private m_GridLineColor As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.Control)
Private m_GridLineStyle As DataGridLineSty le
Private m_HeaderBackCol or As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.Control)
Private m_HeaderFont As Font = New Font("Microsoft Sans Serif", 8.25)
Private m_HeaderForeCol or As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.ControlText)
Private m_LinkColor As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.HotTrack)
Private m_MappingName As String = ""
Private m_PreferredColu mnWidth As Integer = 75
Private m_PreferredRowH eight As Integer = 16
Private m_ReadOnly As Boolean = False
Private m_RowHeadersVis ible As Boolean = True
Private m_RowHeaderWidt h As Integer = 35
Private m_SelectionBack Color As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.ActiveCaption )
Private m_SelectionFore Color As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.ActiveCaption Text)
Private m_Columns As Columns
#End Region

#Region " Component Designer generated code "

Public Sub New(ByVal Container As System.Componen tModel.IContain er)
MyClass.New()

'Required for Windows.Forms Class Composition Designer support
Container.Add(M e)
m_Columns = New Columns
End Sub

Public Sub New()
MyBase.New()

'This call is required by the Component Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call
End Sub

'Component 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.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Component Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
components = New System.Componen tModel.Containe r
End Sub

#End Region

#Region " Properties"

<Description("I ndicates whether sorting is allowed on the grid table when this DataGridTableSt yle is used."), _
Category("Usabi lity")> _
Public Property AllowSorting() As Boolean
Get
Return m_AllowSorting
End Get
Set(ByVal Value As Boolean)
m_AllowSorting = Value
End Set
End Property
<Description("G ets or sets the background color of odd-numbered rows of
the grid."), _
Category("Appea rance")> _
Public Property AlternatingBack Color() As Color
Get
Return m_AlternatingBa ckColor
End Get
Set(ByVal Value As Color)
m_AlternatingBa ckColor = Value
End Set
End Property
<Description("G ets or sets the background color of even-numbered rows of
the grid."), _
Category("Appea rance")> _
Public Property BackColor() As Color
Get
Return m_BackColor
End Get
Set(ByVal Value As Color)
m_BackColor = Value
End Set
End Property
<Description("G ets or sets a value indicating whether column headers are
visible."), _
Category("Appea rance")> _
Public Property ColumnHeadersVi sible() As Boolean
Get
Return m_ColumnHeaders Visible
End Get
Set(ByVal Value As Boolean)
m_ColumnHeaders Visible = Value
End Set
End Property
<Description("G ets or sets the foreground color of the grid table."), _
Category("Appea rance"), _
DefaultValue(Tr ue)> _
Public Property ForeColor() As Color
Get
Return m_ForeColor
End Get
Set(ByVal Value As Color)
m_ForeColor = Value
End Set
End Property
<Description("G ets or sets the color of grid lines."), _
Category("Appea rance")> _
Public Property GridLineColor() As Color
Get
Return m_GridLineColor
End Get
Set(ByVal Value As Color)
m_GridLineColor = Value
End Set
End Property
<Description("G ets or sets the style of grid lines."), _
Category("Appea rance")> _
Public Property GridLineStyle() As DataGridLineSty le
Get
Return m_GridLineStyle
End Get
Set(ByVal Value As DataGridLineSty le)
m_GridLineStyle = Value
End Set
End Property
<Description("G ets or sets the background color of headers."), _
Category("Appea rance")> _
Public Property HeaderBackColor () As Color
Get
Return m_HeaderBackCol or
End Get
Set(ByVal Value As Color)
m_HeaderBackCol or = Value
End Set
End Property
<Description("G ets or sets the font used for header captions."), _
Category("Appea rance")> _
Public Property HeaderFont() As Font
Get
Return m_HeaderFont
End Get
Set(ByVal Value As Font)
m_HeaderFont = Value
End Set
End Property
<Description("G ets or sets the foreground color of headers."), _
Category("Appea rance")> _
Public Property HeaderForeColor () As Color
Get
Return m_HeaderForeCol or
End Get
Set(ByVal Value As Color)
m_HeaderForeCol or = Value
End Set
End Property
<Description("G ets or sets the color of link text."), _
Category("Appea rance")> _
Public Property LinkColor() As Color
Get
Return m_LinkColor
End Get
Set(ByVal Value As Color)
m_LinkColor = Value
End Set
End Property
<Description("G ets or sets the name used to map this table to a specific
data source."), _
Category("Gener al")> _
Public Property MappingName() As String
Get
Return m_MappingName
End Get
Set(ByVal Value As String)
m_MappingName = Value
End Set
End Property
<Description("G ets or sets the width used to create columns when a new
grid is displayed."), _
Category("Gener al")> _
Public Property PreferredColumn Width() As Integer
Get
Return m_PreferredColu mnWidth
End Get
Set(ByVal Value As Integer)
m_PreferredColu mnWidth = Value
End Set
End Property
<Description("G ets or sets the height used to create a row when a new grid is displayed."), _
Category("Appea rance")> _
Public Property PreferredRowHei ght() As Integer
Get
Return m_PreferredRowH eight
End Get
Set(ByVal Value As Integer)
m_PreferredRowH eight = Value
End Set
End Property
<Description("G ets or sets a value indicating whether columns can be
edited."), _
Category("Usabi lity")> _
Public Property [ReadOnly]() As Boolean
Get
Return m_ReadOnly
End Get
Set(ByVal Value As Boolean)
m_ReadOnly = Value
End Set
End Property
<Description("G ets or sets a value indicating whether row headers are
visible."), _
Category("Appea rance")> _
Public Property RowHeadersVisib le() As Boolean
Get
Return m_RowHeadersVis ible
End Get
Set(ByVal Value As Boolean)
m_RowHeadersVis ible = Value
End Set
End Property
<Description("G ets or sets the width of row headers."), _
Category("Appea rance")> _
Public Property RowHeaderWidth( ) As Integer
Get
Return m_RowHeaderWidt h
End Get
Set(ByVal Value As Integer)
m_RowHeaderWidt h = Value
End Set
End Property
<Description("G ets or sets the background color of selected cells."), _
Category("Appea rance")> _
Public Property SelectionBackCo lor() As Color
Get
Return m_SelectionBack Color
End Get
Set(ByVal Value As Color)
m_SelectionBack Color = Value
End Set
End Property
<Description("G ets or sets the foreground color of selected cells."), _
Category("Appea rance")> _
Public Property SelectionForeCo lor() As Color
Get
Return m_SelectionFore Color
End Get
Set(ByVal Value As Color)
m_SelectionFore Color = Value
End Set
End Property
<Description("G ets or sets the collection of columns available for display in the datagrid."), _
Category("Data" ), _
DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Content), _
Editor(GetType( ColumnCollectio nEditor), GetType(UITypeE ditor))> _
Public Property Columns() As Columns
Get
Return m_Columns
End Get
Set(ByVal Value As Columns)
m_Columns = Value
End Set
End Property

#End Region

Friend Class DatatableManage rTypeConverter
Inherits ExpandableObjec tConverter

Public Overloads Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, ByVal value As Object, ByVal
destinationType As System.Type) As Object
Return String.Format(" Data table manager")
End Function

Public Overloads Function CanConvertFrom( ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal sourceType As
System.Type) As Boolean

If (sourceType Is GetType(String) ) Then
Return True
End If

Return MyBase.CanConve rtFrom(context, sourceType)

End Function
End Class

Friend Class DatatableManage rDesigner
Inherits System.Windows. Forms.Design.Co ntrolDesigner

Private MyControl As DatatableManage r

Public Overrides Sub Initialize(ByVa l component As IComponent)

Try
MyBase.Initiali ze(component)

'// Record instance of control we're designing
MyControl = DirectCast(comp onent, DatatableManage r)

'// Hook up events
Dim s As ISelectionServi ce =
DirectCast(GetS ervice(GetType( ISelectionServi ce)), ISelectionServi ce)
Dim c As IComponentChang eService =
DirectCast(GetS ervice(GetType( IComponentChang eService)),
IComponentChang eService)
AddHandler s.SelectionChan ged, New EventHandler(Ad dressOf
OnSelectionChan ged)
AddHandler c.ComponentRemo ving, New ComponentEventH andler(AddressO f OnComponentRemo ving)
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try
End Sub

Private Sub OnSelectionChan ged(ByVal sender As Object, ByVal e As
System.EventArg s)

'MyControl.OnSe lectionChanged( )

End Sub

Private Sub OnComponentRemo ving(ByVal sender As Object, ByVal e As
ComponentEventA rgs)

Try
Dim c As IComponentChang eService =
DirectCast(GetS ervice(GetType( IComponentChang eService)),
IComponentChang eService)
Dim bc As BaseColumn
Dim h As IDesignerHost =
DirectCast(GetS ervice(GetType( IDesignerHost)) , IDesignerHost)

'// If the user is removing a button
If (TypeOf e.Component Is BaseColumn) Then

bc = DirectCast(e.Co mponent, BaseColumn)
If (MyControl.Colu mns.Contains(bc )) Then

c.OnComponentCh anging(MyContro l, Nothing)
MyControl.Colum ns.Remove(bc)
c.OnComponentCh anged(MyControl , Nothing, Nothing, Nothing)
Return
End If
End If

'// If the user is removing the control itself
If (e.Component Is MyControl) Then

For i As Int32 = MyControl.Colum ns.Count - 1 To 0 Step -1

bc = MyControl.Colum ns(i)
c.OnComponentCh anging(MyContro l, Nothing)
MyControl.Colum ns.Remove(bc)
h.DestroyCompon ent(bc)
c.OnComponentCh anged(MyControl , Nothing, Nothing, Nothing)
Next i

End If
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try
End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

Try
Dim s As ISelectionServi ce =
DirectCast(GetS ervice(GetType( ISelectionServi ce)), ISelectionServi ce)
Dim c As IComponentChang eService =
DirectCast(GetS ervice(GetType( IComponentChang eService)),
IComponentChang eService)

'// Unhook events
RemoveHandler s.SelectionChan ged, New EventHandler(Ad dressOf
OnSelectionChan ged)
RemoveHandler c.ComponentRemo ving, New
ComponentEventH andler(AddressO f OnComponentRemo ving)
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try

MyBase.Dispose( disposing)

End Sub

Public Overrides ReadOnly Property AssociatedCompo nents() As
System.Collecti ons.ICollection
Get

Try
Return MyControl.Colum ns
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try

End Get
End Property

Public Overrides ReadOnly Property Verbs() As
System.Componen tModel.Design.D esignerVerbColl ection

Get

Try
Dim v As DesignerVerbCol lection = New DesignerVerbCol lection

'// Verb to add buttons
v.Add(New DesignerVerb("& Add Column", New EventHandler(Ad dressOf
OnAddButton)))

Return v
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try

End Get

End Property

Private Sub OnAddButton(ByV al sender As Object, ByVal e As
System.EventArg s)

Try
Dim bc As BaseColumn
Dim h As IDesignerHost =
DirectCast(GetS ervice(GetType( IDesignerHost)) , IDesignerHost)
Dim dt As DesignerTransac tion
Dim c As IComponentChang eService =
DirectCast(GetS ervice(GetType( IComponentChang eService)),
IComponentChang eService)

'// Add a new button to the collection
dt = h.CreateTransac tion("Add Column")
bc = DirectCast(h.Cr eateComponent(G etType(BaseColu mn)), BaseColumn) c.OnComponentCh anging(MyContro l, Nothing)
MyControl.Colum ns.Add(bc)
c.OnComponentCh anged(MyControl , Nothing, Nothing, Nothing)
dt.Commit()
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try

End Sub

End Class
End Class

#Region " Column Collection "

'<TypeConverter (GetType(Column s.ColumnsTypeCo nverter))>

Public Class Columns
Inherits CollectionBase

Event PropertyChaged( )

'<DesignerSeria lizationVisibil ity(DesignerSer ializationVisib ility.Content)>
Default Public Property Item(ByVal index As Integer) As BaseColumn
Get
Try
Return CType(List(inde x), 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.Collectio n = Me
End Function 'Add

Public Sub AddRange(ByVal Items() As BaseColumn)
Dim Item As Object
For Each Item In Items
CType(Item, BaseColumn).Col lection = Me
list.Add(Item)
Next
End Sub

Public Function IndexOf(ByVal value As BaseColumn) As Integer
Return List.IndexOf(va lue)
End Function 'IndexOf

Public Sub Insert(ByVal index As Integer, ByVal value As BaseColumn)
List.Insert(ind ex, value)
End Sub 'Insert

Public Sub Remove(ByVal value As BaseColumn)
List.Remove(val ue)

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(v alue)
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(ByVa l value As BaseColumn)
'If Not value.GetType() Is Type.GetType("B aseColumn") Then
'Throw New ArgumentExcepti on("value must be of type BaseColumn.",
"value")
'End If
End Sub 'OnValidate

Friend Sub RaisePropertyCh angedEvent()
RaiseEvent PropertyChaged( )
End Sub

Friend Class ColumnsTypeConv erter
Inherits ExpandableObjec tConverter

Public Overloads Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, 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.Componen tModel.ITypeDes criptorContext, ByVal sourceType As
System.Type) As Boolean

If (sourceType Is GetType(String) ) Then
Return True
End If

Return MyBase.CanConve rtFrom(context, sourceType)

End Function
End Class

End Class

#Region " ColumnCollectio nEditor"

Friend Class ColumnCollectio nEditor
Inherits System.Componen tModel.Design.C ollectionEditor

Private Types() As System.Type
Private cf As CollectionForm

Sub New(ByVal type As System.Type)
MyBase.New(type )
Types = New System.Type() {GetType(BaseCo lumn), GetType(TextCol umn),
GetType(CheckCo lumn)}
End Sub

Protected Overrides Function CreateNewItemTy pes() As System.Type()
Return Types
End Function

Protected Overrides Function CreateCollectio nForm() As
System.Componen tModel.Design.C ollectionEditor .CollectionForm
Me.cf = MyBase.CreateCo llectionForm
Return Me.cf
End Function

Protected Overloads Overrides Function CreateInstance( ByVal itemType As
System.Type) As Object

Dim blahblah As BaseColumn = DirectCast(MyBa se.CreateInstan ce(itemType), BaseColumn)

If Not Me.Context.Inst ance Is Nothing Then
End If

Return blahblah

End Function

End Class

#End Region

#Region " Columns Types"

<Serializable() , TypeConverter(G etType(BaseColu mn.BaseColumnCo nverter))> _
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.Horizonta lAlignment
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("G ets or sets the alignment of text in a column."), _
Category("Gener al"), _
DefaultValue(Sy stem.Windows.Fo rms.HorizontalA lignment.Left)> _
Public Property Alignment() As System.Windows. Forms.Horizonta lAlignment
Get
Return m_Alignment
End Get
Set(ByVal Value As System.Windows. Forms.Horizonta lAlignment)
m_Alignment = Value
End Set
End Property

<Description("G ets or sets the text of the column header."), _
Category("Gener al"), _
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("G ets or sets the name used to map the column style to a data member."), _
Category("Gener al"), _
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("G ets or sets the text that is displayed when the column
contains a null reference (Nothing in Visual Basic)."), _
Category("Gener al"), _
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("G ets or sets a value indicating whether the data in the
column can be edited."), _
Category("Gener al"), _
DefaultValue(Tr ue)> _
Public Property [ReadOnly]() As Boolean
Get
Return m_ReadOnly
End Get
Set(ByVal Value As Boolean)
m_ReadOnly = Value
End Set
End Property

<Description("G ets or sets the width of the column."), _
Category("Gener al"), _
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("G ets or sets weather the column should be displayed in the
datagrid."), _
Category("Gener al"), _
DefaultValue(Tr ue)> _
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.Bas e
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.Ra isePropertyChan gedEvent()
End If
End Sub

Public Overrides Function ToString() As String
Return m_MappingName
End Function

#End Region

Friend Class BaseColumnConve rter
Inherits ExpandableObjec tConverter

Public Overloads Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, 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.Componen tModel.ITypeDes criptorContext, ByVal sourceType As
System.Type) As Boolean

If (sourceType Is GetType(String) ) Then
Return True
End If

Return MyBase.CanConve rtFrom(context, sourceType)

End Function

End Class

End Class

<Serializable() , TypeConverter(G etType(TextColu mn.TextColumnCo nverter))> _
Public Class TextColumn
Inherits BaseColumn

Private m_Format As String

<Description("G ets or sets the character(s) that specify how text is
formatted."), _
Category("Gener al"), _
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.Tex t
End Get
End Property

Friend Class TextColumnConve rter
Inherits BaseColumn.Base ColumnConverter
Public Overloads Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, 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(G etType(CheckCol umn.CheckColumn Converter))> _ Public Class CheckColumn
Inherits BaseColumn

Protected m_TrueValue As Object
Protected m_FalseValue As Object

<Description("G ets or sets the actual value used when setting the value of the column to true."), _
Category("Gener al"), _
DefaultValue(Fa lse)> _
Public Property TrueValue() As String
Get
Return CType(m_TrueVal ue, String)
End Get
Set(ByVal Value As String)
m_TrueValue = Value
End Set
End Property

<Description("G ets or sets the actual value used when setting the value of the column to false."), _
Category("Gener al"), _
DefaultValue(Fa lse)> _
Public Property FalseValue() As String
Get
Return CType(m_FalseVa lue, 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.Boo l
End Get
End Property

Friend Class CheckColumnConv erter
Inherits BaseColumn.Base ColumnConverter
Public Overloads Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, 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" <la********@gma il.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Dear all ..

If I want to use develop a user control and declare a public property
which the type is System.Windows. Forms.GridTable StylesCollectio n

For example :

Public Class LookAndView
Inherits System.Windows. Forms.UserContr ol
Private _Collection As GridTableStyles Collection
Public Property Styles() As
System.Windows. Forms.GridTable StylesCollectio n
Get
Return _Collection
End Get
Set(ByVal Value As System.Windows. Forms.GridTable StylesCollectio n) _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


Nov 21 '05 #3
Hi Ambit :

I try to compile you provide sample source..

I find that the problem is find on while I drag the usercontrol on my test
form. The columns value in properties windows show nothing. and when i add
column through collectionedito r also find problem.
It always disappear when leave collectionedito r and reopen again
Any solution about this ?

Thanks

"Lincon Marine Service" <li****@netviga tor.com> 级糶秎ン穝籇: %2************* ***@TK2MSFTNGP0 9.phx.gbl...
Thanks AMDRIT ..

Thank for your help .....very much
I get it and solve this problem

Michael

"AMDRIT" <am****@hotmail .com> 秎ン
news:et******** ******@TK2MSFTN GP09.phx.gbl い级糶...
I am working a very similar project and am running into an issue getting

the
values to save during design time. Perhaps we can share notes?

If anyone else has any ideas where I am going wrong, please let me know.
Thanks.

Here is what I have:

<Serializable() , _
ToolboxItem(Tru e), _
TypeConverter(G etType(Datatabl eManager.Datata bleManagerTypeC onverter))>

_
Public Class DatatableManage r
Inherits System.Componen tModel.Componen t

#Region " Declarations"
Private m_AllowSorting As Boolean = False
Private m_AlternatingBa ckColor As Color = System.Drawing. Color.White
Private m_BackColor As Color = System.Drawing. Color.White
Private m_ColumnHeaders Visible As Boolean = True
Private m_ForeColor As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.WindowText)
Private m_GridLineColor As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.Control)
Private m_GridLineStyle As DataGridLineSty le
Private m_HeaderBackCol or As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.Control)
Private m_HeaderFont As Font = New Font("Microsoft Sans Serif", 8.25)
Private m_HeaderForeCol or As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.ControlText)
Private m_LinkColor As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.HotTrack)
Private m_MappingName As String = ""
Private m_PreferredColu mnWidth As Integer = 75
Private m_PreferredRowH eight As Integer = 16
Private m_ReadOnly As Boolean = False
Private m_RowHeadersVis ible As Boolean = True
Private m_RowHeaderWidt h As Integer = 35
Private m_SelectionBack Color As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.ActiveCaption )
Private m_SelectionFore Color As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.ActiveCaption Text)
Private m_Columns As Columns
#End Region

#Region " Component Designer generated code "

Public Sub New(ByVal Container As System.Componen tModel.IContain er)
MyClass.New()

'Required for Windows.Forms Class Composition Designer support
Container.Add(M e)
m_Columns = New Columns
End Sub

Public Sub New()
MyBase.New()

'This call is required by the Component Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call
End Sub

'Component 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.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Component Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
components = New System.Componen tModel.Containe r
End Sub

#End Region

#Region " Properties"

<Description("I ndicates whether sorting is allowed on the grid table

when
this DataGridTableSt yle is used."), _
Category("Usabi lity")> _
Public Property AllowSorting() As Boolean
Get
Return m_AllowSorting
End Get
Set(ByVal Value As Boolean)
m_AllowSorting = Value
End Set
End Property
<Description("G ets or sets the background color of odd-numbered rows of
the grid."), _
Category("Appea rance")> _
Public Property AlternatingBack Color() As Color
Get
Return m_AlternatingBa ckColor
End Get
Set(ByVal Value As Color)
m_AlternatingBa ckColor = Value
End Set
End Property
<Description("G ets or sets the background color of even-numbered rows
of
the grid."), _
Category("Appea rance")> _
Public Property BackColor() As Color
Get
Return m_BackColor
End Get
Set(ByVal Value As Color)
m_BackColor = Value
End Set
End Property
<Description("G ets or sets a value indicating whether column headers
are
visible."), _
Category("Appea rance")> _
Public Property ColumnHeadersVi sible() As Boolean
Get
Return m_ColumnHeaders Visible
End Get
Set(ByVal Value As Boolean)
m_ColumnHeaders Visible = Value
End Set
End Property
<Description("G ets or sets the foreground color of the grid table."), _
Category("Appea rance"), _
DefaultValue(Tr ue)> _
Public Property ForeColor() As Color
Get
Return m_ForeColor
End Get
Set(ByVal Value As Color)
m_ForeColor = Value
End Set
End Property
<Description("G ets or sets the color of grid lines."), _
Category("Appea rance")> _
Public Property GridLineColor() As Color
Get
Return m_GridLineColor
End Get
Set(ByVal Value As Color)
m_GridLineColor = Value
End Set
End Property
<Description("G ets or sets the style of grid lines."), _
Category("Appea rance")> _
Public Property GridLineStyle() As DataGridLineSty le
Get
Return m_GridLineStyle
End Get
Set(ByVal Value As DataGridLineSty le)
m_GridLineStyle = Value
End Set
End Property
<Description("G ets or sets the background color of headers."), _
Category("Appea rance")> _
Public Property HeaderBackColor () As Color
Get
Return m_HeaderBackCol or
End Get
Set(ByVal Value As Color)
m_HeaderBackCol or = Value
End Set
End Property
<Description("G ets or sets the font used for header captions."), _
Category("Appea rance")> _
Public Property HeaderFont() As Font
Get
Return m_HeaderFont
End Get
Set(ByVal Value As Font)
m_HeaderFont = Value
End Set
End Property
<Description("G ets or sets the foreground color of headers."), _
Category("Appea rance")> _
Public Property HeaderForeColor () As Color
Get
Return m_HeaderForeCol or
End Get
Set(ByVal Value As Color)
m_HeaderForeCol or = Value
End Set
End Property
<Description("G ets or sets the color of link text."), _
Category("Appea rance")> _
Public Property LinkColor() As Color
Get
Return m_LinkColor
End Get
Set(ByVal Value As Color)
m_LinkColor = Value
End Set
End Property
<Description("G ets or sets the name used to map this table to a
specific
data source."), _
Category("Gener al")> _
Public Property MappingName() As String
Get
Return m_MappingName
End Get
Set(ByVal Value As String)
m_MappingName = Value
End Set
End Property
<Description("G ets or sets the width used to create columns when a new
grid is displayed."), _
Category("Gener al")> _
Public Property PreferredColumn Width() As Integer
Get
Return m_PreferredColu mnWidth
End Get
Set(ByVal Value As Integer)
m_PreferredColu mnWidth = Value
End Set
End Property
<Description("G ets or sets the height used to create a row when a new

grid
is displayed."), _
Category("Appea rance")> _
Public Property PreferredRowHei ght() As Integer
Get
Return m_PreferredRowH eight
End Get
Set(ByVal Value As Integer)
m_PreferredRowH eight = Value
End Set
End Property
<Description("G ets or sets a value indicating whether columns can be
edited."), _
Category("Usabi lity")> _
Public Property [ReadOnly]() As Boolean
Get
Return m_ReadOnly
End Get
Set(ByVal Value As Boolean)
m_ReadOnly = Value
End Set
End Property
<Description("G ets or sets a value indicating whether row headers are
visible."), _
Category("Appea rance")> _
Public Property RowHeadersVisib le() As Boolean
Get
Return m_RowHeadersVis ible
End Get
Set(ByVal Value As Boolean)
m_RowHeadersVis ible = Value
End Set
End Property
<Description("G ets or sets the width of row headers."), _
Category("Appea rance")> _
Public Property RowHeaderWidth( ) As Integer
Get
Return m_RowHeaderWidt h
End Get
Set(ByVal Value As Integer)
m_RowHeaderWidt h = Value
End Set
End Property
<Description("G ets or sets the background color of selected cells."), _
Category("Appea rance")> _
Public Property SelectionBackCo lor() As Color
Get
Return m_SelectionBack Color
End Get
Set(ByVal Value As Color)
m_SelectionBack Color = Value
End Set
End Property
<Description("G ets or sets the foreground color of selected cells."), _
Category("Appea rance")> _
Public Property SelectionForeCo lor() As Color
Get
Return m_SelectionFore Color
End Get
Set(ByVal Value As Color)
m_SelectionFore Color = Value
End Set
End Property
<Description("G ets or sets the collection of columns available for

display
in the datagrid."), _
Category("Data" ), _

DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Content),
_
Editor(GetType( ColumnCollectio nEditor), GetType(UITypeE ditor))> _
Public Property Columns() As Columns
Get
Return m_Columns
End Get
Set(ByVal Value As Columns)
m_Columns = Value
End Set
End Property

#End Region

Friend Class DatatableManage rTypeConverter
Inherits ExpandableObjec tConverter

Public Overloads Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, ByVal value As Object, ByVal
destinationType As System.Type) As Object
Return String.Format(" Data table manager")
End Function

Public Overloads Function CanConvertFrom( ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal sourceType As
System.Type) As Boolean

If (sourceType Is GetType(String) ) Then
Return True
End If

Return MyBase.CanConve rtFrom(context, sourceType)

End Function
End Class

Friend Class DatatableManage rDesigner
Inherits System.Windows. Forms.Design.Co ntrolDesigner

Private MyControl As DatatableManage r

Public Overrides Sub Initialize(ByVa l component As IComponent)

Try
MyBase.Initiali ze(component)

'// Record instance of control we're designing
MyControl = DirectCast(comp onent, DatatableManage r)

'// Hook up events
Dim s As ISelectionServi ce =
DirectCast(GetS ervice(GetType( ISelectionServi ce)), ISelectionServi ce)
Dim c As IComponentChang eService =
DirectCast(GetS ervice(GetType( IComponentChang eService)),
IComponentChang eService)
AddHandler s.SelectionChan ged, New EventHandler(Ad dressOf
OnSelectionChan ged)
AddHandler c.ComponentRemo ving, New

ComponentEventH andler(AddressO f
OnComponentRemo ving)
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try
End Sub

Private Sub OnSelectionChan ged(ByVal sender As Object, ByVal e As
System.EventArg s)

'MyControl.OnSe lectionChanged( )

End Sub

Private Sub OnComponentRemo ving(ByVal sender As Object, ByVal e As
ComponentEventA rgs)

Try
Dim c As IComponentChang eService =
DirectCast(GetS ervice(GetType( IComponentChang eService)),
IComponentChang eService)
Dim bc As BaseColumn
Dim h As IDesignerHost =
DirectCast(GetS ervice(GetType( IDesignerHost)) , IDesignerHost)

'// If the user is removing a button
If (TypeOf e.Component Is BaseColumn) Then

bc = DirectCast(e.Co mponent, BaseColumn)
If (MyControl.Colu mns.Contains(bc )) Then

c.OnComponentCh anging(MyContro l, Nothing)
MyControl.Colum ns.Remove(bc)
c.OnComponentCh anged(MyControl , Nothing, Nothing, Nothing)
Return
End If
End If

'// If the user is removing the control itself
If (e.Component Is MyControl) Then

For i As Int32 = MyControl.Colum ns.Count - 1 To 0 Step -1

bc = MyControl.Colum ns(i)
c.OnComponentCh anging(MyContro l, Nothing)
MyControl.Colum ns.Remove(bc)
h.DestroyCompon ent(bc)
c.OnComponentCh anged(MyControl , Nothing, Nothing, Nothing)
Next i

End If
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try
End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

Try
Dim s As ISelectionServi ce =
DirectCast(GetS ervice(GetType( ISelectionServi ce)), ISelectionServi ce)
Dim c As IComponentChang eService =
DirectCast(GetS ervice(GetType( IComponentChang eService)),
IComponentChang eService)

'// Unhook events
RemoveHandler s.SelectionChan ged, New EventHandler(Ad dressOf
OnSelectionChan ged)
RemoveHandler c.ComponentRemo ving, New
ComponentEventH andler(AddressO f OnComponentRemo ving)
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try

MyBase.Dispose( disposing)

End Sub

Public Overrides ReadOnly Property AssociatedCompo nents() As
System.Collecti ons.ICollection
Get

Try
Return MyControl.Colum ns
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try

End Get
End Property

Public Overrides ReadOnly Property Verbs() As
System.Componen tModel.Design.D esignerVerbColl ection

Get

Try
Dim v As DesignerVerbCol lection = New DesignerVerbCol lection

'// Verb to add buttons
v.Add(New DesignerVerb("& Add Column", New
EventHandler(Ad dressOf
OnAddButton)))

Return v
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try

End Get

End Property

Private Sub OnAddButton(ByV al sender As Object, ByVal e As
System.EventArg s)

Try
Dim bc As BaseColumn
Dim h As IDesignerHost =
DirectCast(GetS ervice(GetType( IDesignerHost)) , IDesignerHost)
Dim dt As DesignerTransac tion
Dim c As IComponentChang eService =
DirectCast(GetS ervice(GetType( IComponentChang eService)),
IComponentChang eService)

'// Add a new button to the collection
dt = h.CreateTransac tion("Add Column")
bc = DirectCast(h.Cr eateComponent(G etType(BaseColu mn)),

BaseColumn)
c.OnComponentCh anging(MyContro l, Nothing)
MyControl.Colum ns.Add(bc)
c.OnComponentCh anged(MyControl , Nothing, Nothing, Nothing)
dt.Commit()
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try

End Sub

End Class
End Class

#Region " Column Collection "

'<TypeConverter (GetType(Column s.ColumnsTypeCo nverter))>

Public Class Columns
Inherits CollectionBase

Event PropertyChaged( )

'<DesignerSeria lizationVisibil ity(DesignerSer ializationVisib ility.Content)>

Default Public Property Item(ByVal index As Integer) As BaseColumn
Get
Try
Return CType(List(inde x), 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.Collectio n = Me
End Function 'Add

Public Sub AddRange(ByVal Items() As BaseColumn)
Dim Item As Object
For Each Item In Items
CType(Item, BaseColumn).Col lection = Me
list.Add(Item)
Next
End Sub

Public Function IndexOf(ByVal value As BaseColumn) As Integer
Return List.IndexOf(va lue)
End Function 'IndexOf

Public Sub Insert(ByVal index As Integer, ByVal value As BaseColumn)
List.Insert(ind ex, value)
End Sub 'Insert

Public Sub Remove(ByVal value As BaseColumn)
List.Remove(val ue)

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(v alue)
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(ByVa l value As BaseColumn)
'If Not value.GetType() Is Type.GetType("B aseColumn") Then
'Throw New ArgumentExcepti on("value must be of type BaseColumn.",
"value")
'End If
End Sub 'OnValidate

Friend Sub RaisePropertyCh angedEvent()
RaiseEvent PropertyChaged( )
End Sub

Friend Class ColumnsTypeConv erter
Inherits ExpandableObjec tConverter

Public Overloads Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, 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.Componen tModel.ITypeDes criptorContext, ByVal sourceType As
System.Type) As Boolean

If (sourceType Is GetType(String) ) Then
Return True
End If

Return MyBase.CanConve rtFrom(context, sourceType)

End Function
End Class

End Class

#Region " ColumnCollectio nEditor"

Friend Class ColumnCollectio nEditor
Inherits System.Componen tModel.Design.C ollectionEditor

Private Types() As System.Type
Private cf As CollectionForm

Sub New(ByVal type As System.Type)
MyBase.New(type )
Types = New System.Type() {GetType(BaseCo lumn), GetType(TextCol umn),
GetType(CheckCo lumn)}
End Sub

Protected Overrides Function CreateNewItemTy pes() As System.Type()
Return Types
End Function

Protected Overrides Function CreateCollectio nForm() As
System.Componen tModel.Design.C ollectionEditor .CollectionForm
Me.cf = MyBase.CreateCo llectionForm
Return Me.cf
End Function

Protected Overloads Overrides Function CreateInstance( ByVal itemType As
System.Type) As Object

Dim blahblah As BaseColumn =

DirectCast(MyBa se.CreateInstan ce(itemType),
BaseColumn)

If Not Me.Context.Inst ance Is Nothing Then
End If

Return blahblah

End Function

End Class

#End Region

#Region " Columns Types"

<Serializable() , TypeConverter(G etType(BaseColu mn.BaseColumnCo nverter))>
_
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.Horizonta lAlignment
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("G ets or sets the alignment of text in a column."), _
Category("Gener al"), _
DefaultValue(Sy stem.Windows.Fo rms.HorizontalA lignment.Left)> _
Public Property Alignment() As System.Windows. Forms.Horizonta lAlignment
Get
Return m_Alignment
End Get
Set(ByVal Value As System.Windows. Forms.Horizonta lAlignment)
m_Alignment = Value
End Set
End Property

<Description("G ets or sets the text of the column header."), _
Category("Gener al"), _
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("G ets or sets the name used to map the column style to a

data
member."), _
Category("Gener al"), _
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("G ets or sets the text that is displayed when the column
contains a null reference (Nothing in Visual Basic)."), _
Category("Gener al"), _
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("G ets or sets a value indicating whether the data in the
column can be edited."), _
Category("Gener al"), _
DefaultValue(Tr ue)> _
Public Property [ReadOnly]() As Boolean
Get
Return m_ReadOnly
End Get
Set(ByVal Value As Boolean)
m_ReadOnly = Value
End Set
End Property

<Description("G ets or sets the width of the column."), _
Category("Gener al"), _
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("G ets or sets weather the column should be displayed in
the
datagrid."), _
Category("Gener al"), _
DefaultValue(Tr ue)> _
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.Bas e
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.Ra isePropertyChan gedEvent()
End If
End Sub

Public Overrides Function ToString() As String
Return m_MappingName
End Function

#End Region

Friend Class BaseColumnConve rter
Inherits ExpandableObjec tConverter

Public Overloads Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, 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.Componen tModel.ITypeDes criptorContext, ByVal sourceType As
System.Type) As Boolean

If (sourceType Is GetType(String) ) Then
Return True
End If

Return MyBase.CanConve rtFrom(context, sourceType)

End Function

End Class

End Class

<Serializable() , TypeConverter(G etType(TextColu mn.TextColumnCo nverter))>
_
Public Class TextColumn
Inherits BaseColumn

Private m_Format As String

<Description("G ets or sets the character(s) that specify how text is
formatted."), _
Category("Gener al"), _
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.Tex t
End Get
End Property

Friend Class TextColumnConve rter
Inherits BaseColumn.Base ColumnConverter
Public Overloads Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, 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(G etType(CheckCol umn.CheckColumn Converter))>

_
Public Class CheckColumn
Inherits BaseColumn

Protected m_TrueValue As Object
Protected m_FalseValue As Object

<Description("G ets or sets the actual value used when setting the value

of
the column to true."), _
Category("Gener al"), _
DefaultValue(Fa lse)> _
Public Property TrueValue() As String
Get
Return CType(m_TrueVal ue, String)
End Get
Set(ByVal Value As String)
m_TrueValue = Value
End Set
End Property

<Description("G ets or sets the actual value used when setting the value

of
the column to false."), _
Category("Gener al"), _
DefaultValue(Fa lse)> _
Public Property FalseValue() As String
Get
Return CType(m_FalseVa lue, 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.Boo l
End Get
End Property

Friend Class CheckColumnConv erter
Inherits BaseColumn.Base ColumnConverter
Public Overloads Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, 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" <la********@gma il.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
> Dear all ..
>
> If I want to use develop a user control and declare a public property
> which the type is System.Windows. Forms.GridTable StylesCollectio n
>
> For example :
>
> Public Class LookAndView
> Inherits System.Windows. Forms.UserContr ol
> Private _Collection As GridTableStyles Collection
>
>
> Public Property Styles() As
> System.Windows. Forms.GridTable StylesCollectio n
> Get
> Return _Collection
> End Get
> Set(ByVal Value As System.Windows. Forms.GridTable StylesCollectio n) > _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
>



Nov 21 '05 #4
That is where I am stuck. I cannot seem to find a way to get the properties
to be remembered.
"Michael" <la********@gma il.com> wrote in message
news:Ox******** **********@TK2M SFTNGP09.phx.gb l...
Hi Ambit :

I try to compile you provide sample source..

I find that the problem is find on while I drag the usercontrol on my test
form. The columns value in properties windows show nothing. and when i add
column through collectionedito r also find problem.
It always disappear when leave collectionedito r and reopen again
Any solution about this ?

Thanks

"Lincon Marine Service" <li****@netviga tor.com>
级糶秎ン穝籇: %2************* ***@TK2MSFTNGP0 9.phx.gbl...
Thanks AMDRIT ..

Thank for your help .....very much
I get it and solve this problem

Michael

"AMDRIT" <am****@hotmail .com> 秎ン
news:et******** ******@TK2MSFTN GP09.phx.gbl い级糶...
I am working a very similar project and am running into an issue getting

the
values to save during design time. Perhaps we can share notes?

If anyone else has any ideas where I am going wrong, please let me know.
Thanks.

Here is what I have:

<Serializable() , _
ToolboxItem(Tru e), _

TypeConverter(G etType(Datatabl eManager.Datata bleManagerTypeC onverter))>

_
Public Class DatatableManage r
Inherits System.Componen tModel.Componen t

#Region " Declarations"
Private m_AllowSorting As Boolean = False
Private m_AlternatingBa ckColor As Color = System.Drawing. Color.White
Private m_BackColor As Color = System.Drawing. Color.White
Private m_ColumnHeaders Visible As Boolean = True
Private m_ForeColor As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.WindowText)
Private m_GridLineColor As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.Control)
Private m_GridLineStyle As DataGridLineSty le
Private m_HeaderBackCol or As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.Control)
Private m_HeaderFont As Font = New Font("Microsoft Sans Serif", 8.25)
Private m_HeaderForeCol or As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.ControlText)
Private m_LinkColor As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.HotTrack)
Private m_MappingName As String = ""
Private m_PreferredColu mnWidth As Integer = 75
Private m_PreferredRowH eight As Integer = 16
Private m_ReadOnly As Boolean = False
Private m_RowHeadersVis ible As Boolean = True
Private m_RowHeaderWidt h As Integer = 35
Private m_SelectionBack Color As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.ActiveCaption )
Private m_SelectionFore Color As Color =
System.Drawing. Color.FromKnown Color(KnownColo r.ActiveCaption Text)
Private m_Columns As Columns
#End Region

#Region " Component Designer generated code "

Public Sub New(ByVal Container As System.Componen tModel.IContain er)
MyClass.New()

'Required for Windows.Forms Class Composition Designer support
Container.Add(M e)
m_Columns = New Columns
End Sub

Public Sub New()
MyBase.New()

'This call is required by the Component Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call
End Sub

'Component 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.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Component Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
components = New System.Componen tModel.Containe r
End Sub

#End Region

#Region " Properties"

<Description("I ndicates whether sorting is allowed on the grid table

when
this DataGridTableSt yle is used."), _
Category("Usabi lity")> _
Public Property AllowSorting() As Boolean
Get
Return m_AllowSorting
End Get
Set(ByVal Value As Boolean)
m_AllowSorting = Value
End Set
End Property
<Description("G ets or sets the background color of odd-numbered rows
of
the grid."), _
Category("Appea rance")> _
Public Property AlternatingBack Color() As Color
Get
Return m_AlternatingBa ckColor
End Get
Set(ByVal Value As Color)
m_AlternatingBa ckColor = Value
End Set
End Property
<Description("G ets or sets the background color of even-numbered rows
of
the grid."), _
Category("Appea rance")> _
Public Property BackColor() As Color
Get
Return m_BackColor
End Get
Set(ByVal Value As Color)
m_BackColor = Value
End Set
End Property
<Description("G ets or sets a value indicating whether column headers
are
visible."), _
Category("Appea rance")> _
Public Property ColumnHeadersVi sible() As Boolean
Get
Return m_ColumnHeaders Visible
End Get
Set(ByVal Value As Boolean)
m_ColumnHeaders Visible = Value
End Set
End Property
<Description("G ets or sets the foreground color of the grid table."),
_
Category("Appea rance"), _
DefaultValue(Tr ue)> _
Public Property ForeColor() As Color
Get
Return m_ForeColor
End Get
Set(ByVal Value As Color)
m_ForeColor = Value
End Set
End Property
<Description("G ets or sets the color of grid lines."), _
Category("Appea rance")> _
Public Property GridLineColor() As Color
Get
Return m_GridLineColor
End Get
Set(ByVal Value As Color)
m_GridLineColor = Value
End Set
End Property
<Description("G ets or sets the style of grid lines."), _
Category("Appea rance")> _
Public Property GridLineStyle() As DataGridLineSty le
Get
Return m_GridLineStyle
End Get
Set(ByVal Value As DataGridLineSty le)
m_GridLineStyle = Value
End Set
End Property
<Description("G ets or sets the background color of headers."), _
Category("Appea rance")> _
Public Property HeaderBackColor () As Color
Get
Return m_HeaderBackCol or
End Get
Set(ByVal Value As Color)
m_HeaderBackCol or = Value
End Set
End Property
<Description("G ets or sets the font used for header captions."), _
Category("Appea rance")> _
Public Property HeaderFont() As Font
Get
Return m_HeaderFont
End Get
Set(ByVal Value As Font)
m_HeaderFont = Value
End Set
End Property
<Description("G ets or sets the foreground color of headers."), _
Category("Appea rance")> _
Public Property HeaderForeColor () As Color
Get
Return m_HeaderForeCol or
End Get
Set(ByVal Value As Color)
m_HeaderForeCol or = Value
End Set
End Property
<Description("G ets or sets the color of link text."), _
Category("Appea rance")> _
Public Property LinkColor() As Color
Get
Return m_LinkColor
End Get
Set(ByVal Value As Color)
m_LinkColor = Value
End Set
End Property
<Description("G ets or sets the name used to map this table to a
specific
data source."), _
Category("Gener al")> _
Public Property MappingName() As String
Get
Return m_MappingName
End Get
Set(ByVal Value As String)
m_MappingName = Value
End Set
End Property
<Description("G ets or sets the width used to create columns when a new
grid is displayed."), _
Category("Gener al")> _
Public Property PreferredColumn Width() As Integer
Get
Return m_PreferredColu mnWidth
End Get
Set(ByVal Value As Integer)
m_PreferredColu mnWidth = Value
End Set
End Property
<Description("G ets or sets the height used to create a row when a new

grid
is displayed."), _
Category("Appea rance")> _
Public Property PreferredRowHei ght() As Integer
Get
Return m_PreferredRowH eight
End Get
Set(ByVal Value As Integer)
m_PreferredRowH eight = Value
End Set
End Property
<Description("G ets or sets a value indicating whether columns can be
edited."), _
Category("Usabi lity")> _
Public Property [ReadOnly]() As Boolean
Get
Return m_ReadOnly
End Get
Set(ByVal Value As Boolean)
m_ReadOnly = Value
End Set
End Property
<Description("G ets or sets a value indicating whether row headers are
visible."), _
Category("Appea rance")> _
Public Property RowHeadersVisib le() As Boolean
Get
Return m_RowHeadersVis ible
End Get
Set(ByVal Value As Boolean)
m_RowHeadersVis ible = Value
End Set
End Property
<Description("G ets or sets the width of row headers."), _
Category("Appea rance")> _
Public Property RowHeaderWidth( ) As Integer
Get
Return m_RowHeaderWidt h
End Get
Set(ByVal Value As Integer)
m_RowHeaderWidt h = Value
End Set
End Property
<Description("G ets or sets the background color of selected cells."),
_
Category("Appea rance")> _
Public Property SelectionBackCo lor() As Color
Get
Return m_SelectionBack Color
End Get
Set(ByVal Value As Color)
m_SelectionBack Color = Value
End Set
End Property
<Description("G ets or sets the foreground color of selected cells."),
_
Category("Appea rance")> _
Public Property SelectionForeCo lor() As Color
Get
Return m_SelectionFore Color
End Get
Set(ByVal Value As Color)
m_SelectionFore Color = Value
End Set
End Property
<Description("G ets or sets the collection of columns available for

display
in the datagrid."), _
Category("Data" ), _

DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Content),
_
Editor(GetType( ColumnCollectio nEditor), GetType(UITypeE ditor))> _
Public Property Columns() As Columns
Get
Return m_Columns
End Get
Set(ByVal Value As Columns)
m_Columns = Value
End Set
End Property

#End Region

Friend Class DatatableManage rTypeConverter
Inherits ExpandableObjec tConverter

Public Overloads Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, ByVal value As Object, ByVal
destinationType As System.Type) As Object
Return String.Format(" Data table manager")
End Function

Public Overloads Function CanConvertFrom( ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal sourceType As
System.Type) As Boolean

If (sourceType Is GetType(String) ) Then
Return True
End If

Return MyBase.CanConve rtFrom(context, sourceType)

End Function
End Class

Friend Class DatatableManage rDesigner
Inherits System.Windows. Forms.Design.Co ntrolDesigner

Private MyControl As DatatableManage r

Public Overrides Sub Initialize(ByVa l component As IComponent)

Try
MyBase.Initiali ze(component)

'// Record instance of control we're designing
MyControl = DirectCast(comp onent, DatatableManage r)

'// Hook up events
Dim s As ISelectionServi ce =
DirectCast(GetS ervice(GetType( ISelectionServi ce)), ISelectionServi ce)
Dim c As IComponentChang eService =
DirectCast(GetS ervice(GetType( IComponentChang eService)),
IComponentChang eService)
AddHandler s.SelectionChan ged, New EventHandler(Ad dressOf
OnSelectionChan ged)
AddHandler c.ComponentRemo ving, New

ComponentEventH andler(AddressO f
OnComponentRemo ving)
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try
End Sub

Private Sub OnSelectionChan ged(ByVal sender As Object, ByVal e As
System.EventArg s)

'MyControl.OnSe lectionChanged( )

End Sub

Private Sub OnComponentRemo ving(ByVal sender As Object, ByVal e As
ComponentEventA rgs)

Try
Dim c As IComponentChang eService =
DirectCast(GetS ervice(GetType( IComponentChang eService)),
IComponentChang eService)
Dim bc As BaseColumn
Dim h As IDesignerHost =
DirectCast(GetS ervice(GetType( IDesignerHost)) , IDesignerHost)

'// If the user is removing a button
If (TypeOf e.Component Is BaseColumn) Then

bc = DirectCast(e.Co mponent, BaseColumn)
If (MyControl.Colu mns.Contains(bc )) Then

c.OnComponentCh anging(MyContro l, Nothing)
MyControl.Colum ns.Remove(bc)
c.OnComponentCh anged(MyControl , Nothing, Nothing, Nothing)
Return
End If
End If

'// If the user is removing the control itself
If (e.Component Is MyControl) Then

For i As Int32 = MyControl.Colum ns.Count - 1 To 0 Step -1

bc = MyControl.Colum ns(i)
c.OnComponentCh anging(MyContro l, Nothing)
MyControl.Colum ns.Remove(bc)
h.DestroyCompon ent(bc)
c.OnComponentCh anged(MyControl , Nothing, Nothing, Nothing)
Next i

End If
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try
End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)

Try
Dim s As ISelectionServi ce =
DirectCast(GetS ervice(GetType( ISelectionServi ce)), ISelectionServi ce)
Dim c As IComponentChang eService =
DirectCast(GetS ervice(GetType( IComponentChang eService)),
IComponentChang eService)

'// Unhook events
RemoveHandler s.SelectionChan ged, New EventHandler(Ad dressOf
OnSelectionChan ged)
RemoveHandler c.ComponentRemo ving, New
ComponentEventH andler(AddressO f OnComponentRemo ving)
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try

MyBase.Dispose( disposing)

End Sub

Public Overrides ReadOnly Property AssociatedCompo nents() As
System.Collecti ons.ICollection
Get

Try
Return MyControl.Colum ns
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try

End Get
End Property

Public Overrides ReadOnly Property Verbs() As
System.Componen tModel.Design.D esignerVerbColl ection

Get

Try
Dim v As DesignerVerbCol lection = New DesignerVerbCol lection

'// Verb to add buttons
v.Add(New DesignerVerb("& Add Column", New
EventHandler(Ad dressOf
OnAddButton)))

Return v
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try

End Get

End Property

Private Sub OnAddButton(ByV al sender As Object, ByVal e As
System.EventArg s)

Try
Dim bc As BaseColumn
Dim h As IDesignerHost =
DirectCast(GetS ervice(GetType( IDesignerHost)) , IDesignerHost)
Dim dt As DesignerTransac tion
Dim c As IComponentChang eService =
DirectCast(GetS ervice(GetType( IComponentChang eService)),
IComponentChang eService)

'// Add a new button to the collection
dt = h.CreateTransac tion("Add Column")
bc = DirectCast(h.Cr eateComponent(G etType(BaseColu mn)),

BaseColumn)
c.OnComponentCh anging(MyContro l, Nothing)
MyControl.Colum ns.Add(bc)
c.OnComponentCh anged(MyControl , Nothing, Nothing, Nothing)
dt.Commit()
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try

End Sub

End Class
End Class

#Region " Column Collection "

'<TypeConverter (GetType(Column s.ColumnsTypeCo nverter))>

Public Class Columns
Inherits CollectionBase

Event PropertyChaged( )

'<DesignerSeria lizationVisibil ity(DesignerSer ializationVisib ility.Content)>

Default Public Property Item(ByVal index As Integer) As BaseColumn
Get
Try
Return CType(List(inde x), 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.Collectio n = Me
End Function 'Add

Public Sub AddRange(ByVal Items() As BaseColumn)
Dim Item As Object
For Each Item In Items
CType(Item, BaseColumn).Col lection = Me
list.Add(Item)
Next
End Sub

Public Function IndexOf(ByVal value As BaseColumn) As Integer
Return List.IndexOf(va lue)
End Function 'IndexOf

Public Sub Insert(ByVal index As Integer, ByVal value As BaseColumn)
List.Insert(ind ex, value)
End Sub 'Insert

Public Sub Remove(ByVal value As BaseColumn)
List.Remove(val ue)

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(v alue)
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(ByVa l value As BaseColumn)
'If Not value.GetType() Is Type.GetType("B aseColumn") Then
'Throw New ArgumentExcepti on("value must be of type BaseColumn.",
"value")
'End If
End Sub 'OnValidate

Friend Sub RaisePropertyCh angedEvent()
RaiseEvent PropertyChaged( )
End Sub

Friend Class ColumnsTypeConv erter
Inherits ExpandableObjec tConverter

Public Overloads Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, 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.Componen tModel.ITypeDes criptorContext, ByVal sourceType As
System.Type) As Boolean

If (sourceType Is GetType(String) ) Then
Return True
End If

Return MyBase.CanConve rtFrom(context, sourceType)

End Function
End Class

End Class

#Region " ColumnCollectio nEditor"

Friend Class ColumnCollectio nEditor
Inherits System.Componen tModel.Design.C ollectionEditor

Private Types() As System.Type
Private cf As CollectionForm

Sub New(ByVal type As System.Type)
MyBase.New(type )
Types = New System.Type() {GetType(BaseCo lumn), GetType(TextCol umn),
GetType(CheckCo lumn)}
End Sub

Protected Overrides Function CreateNewItemTy pes() As System.Type()
Return Types
End Function

Protected Overrides Function CreateCollectio nForm() As
System.Componen tModel.Design.C ollectionEditor .CollectionForm
Me.cf = MyBase.CreateCo llectionForm
Return Me.cf
End Function

Protected Overloads Overrides Function CreateInstance( ByVal itemType
As
System.Type) As Object

Dim blahblah As BaseColumn =

DirectCast(MyBa se.CreateInstan ce(itemType),
BaseColumn)

If Not Me.Context.Inst ance Is Nothing Then
End If

Return blahblah

End Function

End Class

#End Region

#Region " Columns Types"

<Serializable() , TypeConverter(G etType(BaseColu mn.BaseColumnCo nverter))>
_
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.Horizonta lAlignment
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("G ets or sets the alignment of text in a column."), _
Category("Gener al"), _
DefaultValue(Sy stem.Windows.Fo rms.HorizontalA lignment.Left)> _
Public Property Alignment() As
System.Windows. Forms.Horizonta lAlignment
Get
Return m_Alignment
End Get
Set(ByVal Value As System.Windows. Forms.Horizonta lAlignment)
m_Alignment = Value
End Set
End Property

<Description("G ets or sets the text of the column header."), _
Category("Gener al"), _
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("G ets or sets the name used to map the column style to a

data
member."), _
Category("Gener al"), _
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("G ets or sets the text that is displayed when the column
contains a null reference (Nothing in Visual Basic)."), _
Category("Gener al"), _
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("G ets or sets a value indicating whether the data in the
column can be edited."), _
Category("Gener al"), _
DefaultValue(Tr ue)> _
Public Property [ReadOnly]() As Boolean
Get
Return m_ReadOnly
End Get
Set(ByVal Value As Boolean)
m_ReadOnly = Value
End Set
End Property

<Description("G ets or sets the width of the column."), _
Category("Gener al"), _
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("G ets or sets weather the column should be displayed in
the
datagrid."), _
Category("Gener al"), _
DefaultValue(Tr ue)> _
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.Bas e
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.Ra isePropertyChan gedEvent()
End If
End Sub

Public Overrides Function ToString() As String
Return m_MappingName
End Function

#End Region

Friend Class BaseColumnConve rter
Inherits ExpandableObjec tConverter

Public Overloads Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, 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.Componen tModel.ITypeDes criptorContext, ByVal sourceType As
System.Type) As Boolean

If (sourceType Is GetType(String) ) Then
Return True
End If

Return MyBase.CanConve rtFrom(context, sourceType)

End Function

End Class

End Class

<Serializable() , TypeConverter(G etType(TextColu mn.TextColumnCo nverter))>
_
Public Class TextColumn
Inherits BaseColumn

Private m_Format As String

<Description("G ets or sets the character(s) that specify how text is
formatted."), _
Category("Gener al"), _
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.Tex t
End Get
End Property

Friend Class TextColumnConve rter
Inherits BaseColumn.Base ColumnConverter
Public Overloads Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, 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(G etType(CheckCol umn.CheckColumn Converter))>

_
Public Class CheckColumn
Inherits BaseColumn

Protected m_TrueValue As Object
Protected m_FalseValue As Object

<Description("G ets or sets the actual value used when setting the
value

of
the column to true."), _
Category("Gener al"), _
DefaultValue(Fa lse)> _
Public Property TrueValue() As String
Get
Return CType(m_TrueVal ue, String)
End Get
Set(ByVal Value As String)
m_TrueValue = Value
End Set
End Property

<Description("G ets or sets the actual value used when setting the
value

of
the column to false."), _
Category("Gener al"), _
DefaultValue(Fa lse)> _
Public Property FalseValue() As String
Get
Return CType(m_FalseVa lue, 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.Boo l
End Get
End Property

Friend Class CheckColumnConv erter
Inherits BaseColumn.Base ColumnConverter
Public Overloads Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, 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" <la********@gma il.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
> Dear all ..
>
> If I want to use develop a user control and declare a public property
> which the type is System.Windows. Forms.GridTable StylesCollectio n
>
> For example :
>
> Public Class LookAndView
> Inherits System.Windows. Forms.UserContr ol
> Private _Collection As GridTableStyles Collection
>
>
> Public Property Styles() As
> System.Windows. Forms.GridTable StylesCollectio n
> Get
> Return _Collection
> End Get
> Set(ByVal Value As

System.Windows. Forms.GridTable StylesCollectio n)
> _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
>



Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3699
by: Doug | last post by:
I'm trying to create a user control that would have a ListDictionary property. When trying to use the property and set values for this collection, the dialog box that appears has everything disabled. I'm unsure of what I have to have set in code in order to enable this??
0
622
by: Colin | last post by:
Hi there, I really need your help on this. I'm trying to learn to using the VS.2003 to create a User Control. In my aspx code has no problem to use the property "grossWaye" that has "register" in the aspx code if I don't use "Codebehind" directive. If I try to move the <script></script> coding the Codebehind of the VS2003. I don't know how to get the property "grossWaye". I post both User Control and .aspx codes for your help. Thanks in...
2
2513
by: Edward Diener | last post by:
In C++ an overridden virtual function in a derived class must have the exact same signature of the function which is overridden in the base class, except for the return type which may return a pointer or reference to a derived type of the base class's return type. In .NET the overridden virtual function is similar, but an actual parameter of the function can be a derived reference from the base class's reference also. This dichotomy...
2
2135
by: Tim Pacl | last post by:
I am building a Custom Placeholder control for MCMS 2002 which gives a translucent background to the control. I want to add a "Style" property and use the standard style editor which is available in numerous other server controls. What is the editor used for the style collection? I tried System.ComponentModel.Design.CollectionEditor but, of course, that isn't it. I have searched the internet and MSDN in vain for two days. Lots of info...
2
3020
by: paul meaney | last post by:
All, myself and another developer have been staring blankly at a screen for the past 48 hours and are wondering just what stunningly obvious thing we are missing. We are trying to load up 2 or more user controls dynamically by adding to a placeholder defined in page_load. I've included the sample code for how we are accessing one. The user controls are not rocket science - just a few text boxes with public accessor properties. We've...
2
3172
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the problems that I have encountered to date and the solutions (if any) that I found. http://users.adelphia.net/~brianpclab/ServerControlCollectionIssues.htm This page also has all of the source code in a compressed file that you are free to download...
3
4312
by: Shimon Sim | last post by:
I have control. One of the properties is implemented as StringCollection. I didn't use any Editor attribute for it. During Design time system shows dialog similar to Items in DropDownList but Add button throws an error "Constructor on type System.String not found.". I may understand this message - there are too many contractor and non of them takes string. But how can I fix the problem or may be use the editor similar to Font.Names...
2
4063
by: Marco de Vries | last post by:
I have a user control and I want to add some properties in design time using a Colelction editor. I defined a type and collection for example. Public Class TestDefinition ... properties get/set End Class Public Class TestCollection inherits collectionbase
2
1766
by: Michael | last post by:
Dear All : I have a problem about define property GridTableStylesCollection in usercontrol. The code show as follow : Public Property StylesCollector() As GridTableStylesCollection Set(ByVal Value As GridTableStylesCollection) _GridStyleCollection= Value End Set
0
8619
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we抣l explore What is ONU, What Is Router, ONU & Router抯 main usage, and What is the difference between ONU and Router. Let抯 take a closer look ! Part I. Meaning of...
0
8555
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9112
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8971
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8824
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7651
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project梡lanning, coding, testing, and deployment梬ithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4336
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4571
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2994
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.