473,703 Members | 2,324 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Designtime Support with Custom Component

Hello everyone,

I have created a custom component and one of its properties is a class
object with it's own properties. During runtime, I can assign values to the
class object properties just fine. However, when attempting to assing
default values as designtime in the propertygrid, nothing is working on the
class object. I know that I am doing it wrong, any ideas what it is?

Thanks in advance

Public Class somecontrol
Inherits System.Windows. Forms.UserContr ol

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

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

'Add any initialization after the InitializeCompo nent() call

End Sub

'UserControl 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 Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Private WithEvents sc As ControlLib.some component
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.components = New System.Componen tModel.Containe r
Dim resources As System.Resource s.ResourceManag er = New
System.Resource s.ResourceManag er(GetType(some control))
Me.sc = New ControlLib.some component(Me.co mponents)
'
'sc
'
Me.sc.Testing = "test"
'
'somecontrol
'
Me.Name = "somecontro l"

End Sub

#End Region

End Class

Imports System.Componen tModel
Imports System.Componen tModel.Design ' Custom Designers Require this
NameSpace
Imports System.Componen tModel.Design.S erialization ' Instance Descriptors

<Serializable() > _
Public Class somecomponent
Inherits System.Componen tModel.Componen t

Private m_testing As String
Private m_MoreInformati on As MoreInformation

#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)
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
m_MoreInformati on = New MoreInformation
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

Public Property Testing() As String
Get
Return m_testing
End Get
Set(ByVal Value As String)
m_testing = Value
End Set
End Property

<Browsable(True ), Bindable(True),
DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Content)> _
Public Property MoreInformation () As MoreInformation
Get
Return m_MoreInformati on
End Get
Set(ByVal Value As MoreInformation )
m_MoreInformati on = Value
End Set
End Property

End Class

<Serializable() > _
Public Class MoreInformation

Private m_property1 As String
Private m_property2 As Long

Public Sub New()
m_property1 = ""
m_property2 = 0
End Sub

Public Property Porperty1() As String
Get
Return m_property1
End Get
Set(ByVal Value As String)
m_property1 = Value
End Set
End Property

Public Property Property2() As Long
Get
Return m_property2
End Get
Set(ByVal Value As Long)
m_property2 = Value
End Set
End Property

End Class


Nov 21 '05 #1
2 2442
Nevermind, I figured it out. I needed a type converter. I knew that much,
I was just having an issue getting it to work.

For those of you keeping score at home

<Serializable() ,
TypeConverter(G etType(MoreInfo rmation.MoreInf ormationTypeCon verter))> _
Public Class MoreInformation

Private m_property1 As String
Private m_property2 As Long

Public Sub New()
m_property1 = ""
m_property2 = 0
End Sub

Public Property Porperty1() As String
Get
Return m_property1
End Get
Set(ByVal Value As String)
m_property1 = Value
End Set
End Property

Public Property Property2() As Long
Get
Return m_property2
End Get
Set(ByVal Value As Long)
m_property2 = Value
End Set
End Property

Friend Class MoreInformation TypeConverter
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 MoreInformation = CType(value, MoreInformation )
Return String.Format(" {0}, {1}", mi.m_property1, mi.m_property2)
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
"AMDRIT" <am****@hotmail .com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hello everyone,

I have created a custom component and one of its properties is a class
object with it's own properties. During runtime, I can assign values to
the class object properties just fine. However, when attempting to
assing default values as designtime in the propertygrid, nothing is
working on the class object. I know that I am doing it wrong, any ideas
what it is?

Thanks in advance

Public Class somecontrol
Inherits System.Windows. Forms.UserContr ol

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

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

'Add any initialization after the InitializeCompo nent() call

End Sub

'UserControl 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 Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Private WithEvents sc As ControlLib.some component
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.components = New System.Componen tModel.Containe r
Dim resources As System.Resource s.ResourceManag er = New
System.Resource s.ResourceManag er(GetType(some control))
Me.sc = New ControlLib.some component(Me.co mponents)
'
'sc
'
Me.sc.Testing = "test"
'
'somecontrol
'
Me.Name = "somecontro l"

End Sub

#End Region

End Class

Imports System.Componen tModel
Imports System.Componen tModel.Design ' Custom Designers Require this
NameSpace
Imports System.Componen tModel.Design.S erialization ' Instance Descriptors

<Serializable() > _
Public Class somecomponent
Inherits System.Componen tModel.Componen t

Private m_testing As String
Private m_MoreInformati on As MoreInformation

#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)
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
m_MoreInformati on = New MoreInformation
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

Public Property Testing() As String
Get
Return m_testing
End Get
Set(ByVal Value As String)
m_testing = Value
End Set
End Property

<Browsable(True ), Bindable(True),
DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Content)>
_
Public Property MoreInformation () As MoreInformation
Get
Return m_MoreInformati on
End Get
Set(ByVal Value As MoreInformation )
m_MoreInformati on = Value
End Set
End Property

End Class

<Serializable() > _
Public Class MoreInformation

Private m_property1 As String
Private m_property2 As Long

Public Sub New()
m_property1 = ""
m_property2 = 0
End Sub

Public Property Porperty1() As String
Get
Return m_property1
End Get
Set(ByVal Value As String)
m_property1 = Value
End Set
End Property

Public Property Property2() As Long
Get
Return m_property2
End Get
Set(ByVal Value As Long)
m_property2 = Value
End Set
End Property

End Class

Nov 21 '05 #2
Hi Gang,

Help me out here, this is not working. I do not know what I am missing and
where i am going wrong. I realize there is a lot of code in it. The
problem is that the property values for DatatableManage r are not remembered
from design time to run time when added to the ucGrid, more over when I add
the ucGrid to a form, the properties are not written in the Initialize
Component section.
TIA

Imports System
Imports System.Collecti ons
Imports System.Componen tModel
Imports System.Componen tModel.Design ' Custom Designers Require this
NameSpace
Imports System.Componen tModel.Design.S erialization ' Instance Descriptors
Imports System.Globaliz ation ' This name space is required for
Imports System.Drawing. Design ' Designers Are in this NameSpace, You Also
need to a reference to System.Design.D ll

Public Class ucDatagrid
Inherits System.Windows. Forms.UserContr ol

Private m_datatable As DataTable

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

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

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

'UserControl 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 Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Protected Friend WithEvents dbgData As DataGrid
Protected Friend WithEvents mnuGrid As System.Windows. Forms.ContextMe nu
Protected Friend WithEvents m_DatatableMana ger As
ControlLib.Data tableManager
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.components = New System.Componen tModel.Containe r
Dim resources As System.Resource s.ResourceManag er = New
System.Resource s.ResourceManag er(GetType(ucDa tagrid))
Me.dbgData = New System.Windows. Forms.DataGrid
Me.mnuGrid = New System.Windows. Forms.ContextMe nu
Me.m_DatatableM anager = New ControlLib.Data tableManager(Me .components)
CType(Me.dbgDat a, System.Componen tModel.ISupport Initialize).Beg inInit()
Me.SuspendLayou t()
'
'dbgData
'
Me.dbgData.Data Member = ""
Me.dbgData.Dock = System.Windows. Forms.DockStyle .Fill
Me.dbgData.Head erForeColor = System.Drawing. SystemColors.Co ntrolText
Me.dbgData.Loca tion = New System.Drawing. Point(0, 0)
Me.dbgData.Name = "dbgData"
Me.dbgData.Size = New System.Drawing. Size(296, 240)
Me.dbgData.TabI ndex = 0
'
'm_DatatableMan ager
'
Me.m_DatatableM anager.AllowSor ting = True
Me.m_DatatableM anager.Alternat ingBackColor = System.Drawing. Color.Empty
Me.m_DatatableM anager.BackColo r = System.Drawing. Color.Empty
Me.m_DatatableM anager.ColumnHe adersVisible = True
Me.m_DatatableM anager.Columns. AddRange(New ControlLib.Base Column()
{CType(resource s.GetObject("re source"), ControlLib.Base Column)})
Me.m_DatatableM anager.ForeColo r = System.Drawing. Color.Empty
Me.m_DatatableM anager.GridLine Color = System.Drawing. Color.Empty
Me.m_DatatableM anager.GridLine Style =
System.Windows. Forms.DataGridL ineStyle.None
Me.m_DatatableM anager.HeaderBa ckColor = System.Drawing. Color.Empty
Me.m_DatatableM anager.HeaderFo nt = Nothing
Me.m_DatatableM anager.HeaderFo reColor = System.Drawing. Color.Empty
Me.m_DatatableM anager.LinkColo r = System.Drawing. Color.Empty
Me.m_DatatableM anager.MappingN ame = Nothing
Me.m_DatatableM anager.Preferre dColumnWidth = 0
Me.m_DatatableM anager.Preferre dRowHeight = 0
Me.m_DatatableM anager.ReadOnly = False
Me.m_DatatableM anager.RowHeade rsVisible = False
Me.m_DatatableM anager.RowHeade rWidth = 0
Me.m_DatatableM anager.Selectio nBackColor = System.Drawing. Color.Empty
Me.m_DatatableM anager.Selectio nForeColor = System.Drawing. Color.Empty
'
'ucDatagrid
'
Me.Controls.Add (Me.dbgData)
Me.Name = "ucDatagrid "
Me.Size = New System.Drawing. Size(296, 240)
CType(Me.dbgDat a, System.Componen tModel.ISupport Initialize).End Init()
Me.ResumeLayout (False)

End Sub

#End Region

Public WriteOnly Property Datasource() As DataTable
Set(ByVal Value As DataTable)

End Set
End Property

<DesignerSerial izationVisibili ty(DesignerSeri alizationVisibi lity.Content)>
_
Public Property DatatableManage r() As DatatableManage r
Get
Return m_DatatableMana ger
End Get
Set(ByVal Value As DatatableManage r)
m_DatatableMana ger = Value
End Set
End Property

End Class

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

#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)
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
m_Columns = New Columns

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 " Declarations"
Private m_AllowSorting As Boolean
Private m_AlternatingBa ckColor As Color
Private m_BackColor As Color
Private m_ColumnHeaders Visible As Boolean
Private m_ForeColor As Color
Private m_GridLineColor As Color
Private m_GridLineStyle As DataGridLineSty le
Private m_HeaderBackCol or As Color
Private m_HeaderFont As Font
Private m_HeaderForeCol or As Color
Private m_LinkColor As Color
Private m_MappingName As String
Private m_PreferredColu mnWidth As Integer
Private m_PreferredRowH eight As Integer
Private m_ReadOnly As Boolean
Private m_RowHeadersVis ible As Boolean
Private m_RowHeaderWidt h As Integer
Private m_SelectionBack Color As Color
Private m_SelectionFore Color As Color
Private m_Columns As Columns
#End Region

#Region " Properties"

<Description("I ndicates whether sorting is allowed on the grid table when
this DataGridTableSt yle is used."), _
Category("Usabi lity"), _
DefaultValue(Fa lse)> _
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"), _
DefaultValue(Kn ownColor.Window )> _
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"), _
DefaultValue(Kn ownColor.Red)> _
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"), _
DefaultValue(Tr ue)> _
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"), _
DefaultValue(Tr ue)> _
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"), _
DefaultValue(Tr ue)> _
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"), _
DefaultValue(Tr ue)> _
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"), _
DefaultValue(Tr ue)> _
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"), _
DefaultValue(Tr ue)> _
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"), _
DefaultValue(Tr ue)> _
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"), _
DefaultValue(Tr ue)> _
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"), _
DefaultValue(Tr ue)> _
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"), _
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 a value indicating whether row headers are
visible."), _
Category("Appea rance"), _
DefaultValue(Tr ue)> _
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"), _
DefaultValue(Tr ue)> _
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"), _
DefaultValue(Tr ue)> _
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"), _
DefaultValue(Tr ue)> _
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" ), Browsable(True) , Bindable(True),
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

End Class

#Region " Column Collection "

<Serializable() , TypeConverter(G etType(Columns. ColumnsTypeConv erter))> _
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)
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

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

End Class

#End Region

#Region " Columns Types"

<Serializable() , TypeConverter(G etType(BaseColu mn.BaseColumnCo nverter))> _
Public Class BaseColumn

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(Fals e)> Public Property ColumnType() As ColumnTypes
Get
Return m_ColumnType
End Get
Set(ByVal Value As ColumnTypes)
m_ColumnType = Value
End Set
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

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

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
"AMDRIT" <am****@hotmail .com> wrote in message
news:u%******** *******@tk2msft ngp13.phx.gbl.. .
Nevermind, I figured it out. I needed a type converter. I knew that
much, I was just having an issue getting it to work.

For those of you keeping score at home

<Serializable() ,
TypeConverter(G etType(MoreInfo rmation.MoreInf ormationTypeCon verter))> _
Public Class MoreInformation

Private m_property1 As String
Private m_property2 As Long

Public Sub New()
m_property1 = ""
m_property2 = 0
End Sub

Public Property Porperty1() As String
Get
Return m_property1
End Get
Set(ByVal Value As String)
m_property1 = Value
End Set
End Property

Public Property Property2() As Long
Get
Return m_property2
End Get
Set(ByVal Value As Long)
m_property2 = Value
End Set
End Property

Friend Class MoreInformation TypeConverter
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 MoreInformation = CType(value, MoreInformation )
Return String.Format(" {0}, {1}", mi.m_property1, mi.m_property2)
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
"AMDRIT" <am****@hotmail .com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hello everyone,

I have created a custom component and one of its properties is a class
object with it's own properties. During runtime, I can assign values to
the class object properties just fine. However, when attempting to
assing default values as designtime in the propertygrid, nothing is
working on the class object. I know that I am doing it wrong, any ideas
what it is?

Thanks in advance

Public Class somecontrol
Inherits System.Windows. Forms.UserContr ol

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

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

'Add any initialization after the InitializeCompo nent() call

End Sub

'UserControl 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 Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Private WithEvents sc As ControlLib.some component
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.components = New System.Componen tModel.Containe r
Dim resources As System.Resource s.ResourceManag er = New
System.Resource s.ResourceManag er(GetType(some control))
Me.sc = New ControlLib.some component(Me.co mponents)
'
'sc
'
Me.sc.Testing = "test"
'
'somecontrol
'
Me.Name = "somecontro l"

End Sub

#End Region

End Class

Imports System.Componen tModel
Imports System.Componen tModel.Design ' Custom Designers Require this
NameSpace
Imports System.Componen tModel.Design.S erialization ' Instance Descriptors

<Serializable() > _
Public Class somecomponent
Inherits System.Componen tModel.Componen t

Private m_testing As String
Private m_MoreInformati on As MoreInformation

#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)
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
m_MoreInformati on = New MoreInformation
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

Public Property Testing() As String
Get
Return m_testing
End Get
Set(ByVal Value As String)
m_testing = Value
End Set
End Property

<Browsable(True ), Bindable(True),
DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Content)>
_
Public Property MoreInformation () As MoreInformation
Get
Return m_MoreInformati on
End Get
Set(ByVal Value As MoreInformation )
m_MoreInformati on = Value
End Set
End Property

End Class

<Serializable() > _
Public Class MoreInformation

Private m_property1 As String
Private m_property2 As Long

Public Sub New()
m_property1 = ""
m_property2 = 0
End Sub

Public Property Porperty1() As String
Get
Return m_property1
End Get
Set(ByVal Value As String)
m_property1 = Value
End Set
End Property

Public Property Property2() As Long
Get
Return m_property2
End Get
Set(ByVal Value As Long)
m_property2 = Value
End Set
End Property

End Class


Nov 21 '05 #3

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

Similar topics

0
1793
by: Rahail | last post by:
Hello, I have a question, can someone help me please? What are the differences between a runtime and a designtime component? Is runtime component only good for running with the .exe and not during development environment using Visual Basic 6 (For example, an error pops out saying License is not found - I am using 3rd party components.)?
0
1559
by: ttupper | last post by:
I have made a custom control that has a property that is a custom component. When I put the custom control on a form in the designer, the propery is listed in the Properties window with a default value of (none). I then put the custom component on the form and it goes in the Component tray like it is supposed to. I then drop down the property on the custom control and the only value ni the list is (none).
0
1268
by: stew_mclean | last post by:
Hi, I've developed a class that derives from component (rather than a control), and am trying to license it at design time. I've set the license attributes etc. to my custom license provider: The problem is that my license provider never gets called at designtime. To prove this, I've put this code into the implementation
1
3060
by: Felix_WafyTech | last post by:
Hi, I'm working with the ObjectDatasource and the application is getting more and more chatty. Is there a way I could make the ObjectDatasource support multiple DataTables that could be retrieved as one Dataset? I'm wondering how others out there work with ObjectDatasource? The only option I now see to get this fixed is to manually make the call to the Web services, retrieve the Dataset and assign the datatable to the controls (Or can...
1
922
by: wapsiii | last post by:
I'd like to add comment attributes to a custom server control (the little help text/tooltip that appears for some server controls at the bottom of the properties pane in vs) How is this possible? <HelpText... Property x() as string get... set...
2
5065
by: Steve | last post by:
This is a weird one. I have a series of "SmartParts" which are CAB (Composite Application Block) Views which are finally just UserControls (99% of the time) Anyway, I layout my UserControl in the VS2005 designer, but at runtime, the controls are in different locations and different sizes. I have been able to restore their sizes by putting a hack together that will set their sizes to the correct values in the UserControl's Resize...
2
1699
by: rotsj | last post by:
Hello, I would like to make my own dropdownlist and add a collection as a generic List. When I enter items @ designtime, @ runtime they are gone. Can anyone tell me please what the problem is? This is my code:
2
1707
by: Johnny Jörgensen | last post by:
I would like to be able to tell whether my component code is executed when I instanciate a control in runtime or in designtime. Can anybody give me a clua as to how you can do that? Cheers, Johnny J.
0
1667
by: Michael Meier | last post by:
1. i have written a component that needs to read information from a file. 2. the project that uses the component gives the file to to component via a property 3. problem is, that this property must not be an absolut path but a relative one. at runtime this is no big problem, i expect the input file to be relative to the starting .exe whose path i get via Application.StartupPath. but what about DesignTime? when i use my component in...
0
9254
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
9122
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
9017
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,...
1
6592
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5923
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3125
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
2
2458
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2070
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.