Friend Sub MasKit(ByVal cols As DataColumnCollection) > For Each Ctrl In Me.Controls > If (TypeOf Ctrl Is IControlMaskit) Then > Dim icm As IControlMaskit = CType(Ctrl, IControlMaskit) > If icm.Mask <> "" Then > Exit Sub > End If > > Dim B As Binding = Ctrl.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 c.MaxLength can be negative..... > icm.Mask = ">" & New String("A", c.MaxLength) > Case GetType(System.DateTime) > icm.Mask = ">##/AAA/##" > End Select > End If > Next > End Sub >End Class > >Public Interface IControlMaskit > Property Mask() As String >End InterfaceThis would also allow you to use this with controls other than just TextBox...
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)