Friend Sub MasKit(ByVal cols As DataColumnCollection) > For Each Ctrl In Me.Controls > If (TypeOf Ctrl Is IControlMaskit) Then > CType(Ctrl, IControlMaskit).MaskIt(cols) > End If > Next > End Sub
Friend Sub MaskIt(ByVal cols As DataColumnCollection) Implements IControlMaskit.MaskIt > If Me.Mask <> "" Then > Exit Sub > End If > > Dim B As Binding = Me.DataBindings.Item(0) > > Dim O As Object = B.DataSource > If Not (TypeOf O Is DataTable) Then > O = CType(O, DataView).Table > End If > > Dim c As DataColumn = CType(O, DataTable).Columns(B.BindingMemberInfo.BindingField) > > Select Case c.DataType > Case GetType(System.String) > ' Possible error since MaxLength can be negative..... > Me.Mask = ">" & New String("A", c.MaxLength) > Case GetType(System.DateTime) > Me.Mask = ">##/AAA/##" > End Select > End SubIf not then at least it's a bit shorter (s)
>> Private Sub frmXXX_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load >> Me.MasKit(Me.XXXDataset.XXX.Columns) >> End Sub >>>>
>> Friend Sub MasKit(ByVal cols As DataColumnCollection) >> Dim ctrl2 As IControlMaskit = Nothing >> For Each Ctrl As Control In Me.Controls >> Dim lApplicable As Boolean = True >> Try >> ctrl2 = Ctrl >> Catch >> lApplicable = False >> End Try >> If lApplicable Then >> ctrl2.MaskIt(cols) >> End If >> Next >> End Sub >>>>
>> Friend Sub MaskIt(ByVal cols As DataColumnCollection) Implements IControlMaskit.MaskIt >> If Me.Mask <> "" Then >> Exit Sub >> End If >> >> Dim B As Binding = Me.DataBindings.Item(0) >> Dim t As DataTable = CType(B.DataSource, DataTable) >> Dim c As DataColumn = Nothing >> >> If t Is Nothing Then >> Dim t1 As DataView = B.DataSource >> c = t1.Columns(B.BindingMemberInfo.BindingField) >> Else >> c = t.Columns(Me.DataBindings.Item(0).BindingMemberInfo.BindingField) >> End If >> >> ' Dim o As DataColumn = cols(Me.DataBindings.Item(0).BindingMemberInfo.BindingField) >> Dim cT As String = c.DataType.ToString >> If cT = "System.String" Then >> Me.Mask = ">" & New String("A", c.MaxLength) >> Exit Sub >> End If >> If cT = "System.DateTime" Then >> Me.Mask = ">##/AAA/##" >> Exit Sub >> End If >> MsgBox(Me.Name & " cannot be masked yet (" & cT & ")") >> End Sub >>>>