Click here to Skip to main content
15,888,579 members
Articles / Desktop Programming / WPF

CurionLib Dynamic Data Entry Forms

Rate me:
Please Sign up or sign in to vote.
5.00/5 (20 votes)
11 Aug 2013CPOL16 min read 54.7K   5.5K   44  
Dynamic data forms.
Namespace Data.List
	Public Class Column
		Implements IDisposable
		' Default use a function GetValue.  It also supports simple value setting with SetFixedDefault
		' So values can be defaulted to things like Today, New Guid(), NextSequence, etc
#Region "  Private fields "
		Private _parent As DataList
		Private _name As String = String.Empty
		Private _fixedDefault As Object = String.Empty
		Private _default As GetValue = AddressOf ADefault
		Delegate Function GetValue() As Object
#End Region
		Sub New(parent As DataList, name As String, Optional header As String = "", Optional type As Type = Nothing, Optional width As Integer = 0, Optional isRequired As Boolean = False)
			If parent Is Nothing Then Throw New InvalidConstraintException("parent is required")
			_parent = parent
			_name = name
			If type Is Nothing Then type = GetType(String)
			Me.Type = type
			If header = String.Empty Then Me.Header = _name Else Me.Header = header
			Me.Width = width
			Me.IsRequired = isRequired
		End Sub
		Sub New(parent As DataList, name As String, defaultValue As Object, Optional header As String = "", Optional type As Type = Nothing, Optional width As Integer = 0, Optional isRequired As Boolean = False)
			If parent Is Nothing Then Throw New InvalidConstraintException("parent is required")
			_parent = parent
			_name = name
			If type Is Nothing Then type = String.Empty.GetType
			Me.Type = type
			If header = String.Empty Then Me.Header = _name Else Me.Header = header
			Me.Width = width
			Me.IsRequired = isRequired
			Call SetFixedDefault(defaultValue)
		End Sub
		Public Sub SetFixedDefault(value As Object)
			_fixedDefault = value
			Me.DefaultValue = AddressOf GetFixedDefault
		End Sub
		Public Property DefaultValue As GetValue
			Get
				Return _default
			End Get
			Set(value As GetValue)
				_default = value
			End Set
		End Property
		Public ReadOnly Property List As DataList
			Get
				Return _parent
			End Get
		End Property
		Public ReadOnly Property Name As String
			Get
				Return _name
			End Get
		End Property
		Public Property Header As String
		Public Property Width As String
		Public Property IsRequired As Boolean
		Public Property Type As Type
		Public ReadOnly Property Index As Integer
			Get
				Return _parent.Columns.Index(_name)
			End Get
		End Property
#Region "  Support routines "
		Private Function GetFixedDefault() As Object
			Return _fixedDefault
		End Function
		Private Function ADefault() As Object
			Return Nothing
		End Function
		Private disposedValue As Boolean ' To detect redundant calls
		Protected Overridable Sub Dispose(disposing As Boolean)
			If Not Me.disposedValue Then
				If disposing Then
					_parent = Nothing
					_name = String.Empty
					_fixedDefault = Nothing
					_default = Nothing
				End If
			End If
			Me.disposedValue = True
		End Sub
		Public Sub Dispose() Implements IDisposable.Dispose
			' Do not change this code.  Put cleanup code in Dispose(disposing As Boolean) above.
			Dispose(True)
			GC.SuppressFinalize(Me)
		End Sub
#End Region
	End Class
End Namespace

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
I enjoy my wife, living in the woods, my 7 dogs, and learning new things. I like to play with UI stuff and model based coding.

Comments and Discussions