Private Sub frmXXX_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.MasKit(Me.XXXDataset.XXX.Columns) End Subso, cols is really Me.XXXDataset.XXX.Columns is a DataColumnCollection, belonging to a datatable ... I think.
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 Suband at the txtBase level (inferring from your wise advice ...)
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 SubNow this won't compile because "columns is not a member of 'system.data.dataview', and leaving out the dataview section does not work. (I don't think I need the dataview section). When I debug, B.Datasource does not seem to be set (in fact it returns "nothing", your "null" I guess?)
>// oBinding is simply what the TextBox is bound to >// Me.DataBindings.Item(0) in your example > >int nRow = this.BindingContext[this.oBinding.DataSource].Position; >string field = this.oBinding.BindingMemberInfo.BindingField; > >DataTable table = null; >if (this.oBinding.DataSource is DataView) >{ > nRow = CommonFunctions.IndexOfRow((DataView)this.oBinding.DataSource, nRow); > table = ((DataView)this.oBinding.DataSource).Table; >} >else > if (this.oBinding.DataSource is DataTable) > table = (DataTable)this.oBinding.DataSource; >>
>>Me.DataBindings.Item(0).BindingMemberInfo.BindingField >>>>
>>Dim o As DataColumn = cols(Me.DataBindings.Item(0).BindingMemberInfo.BindingField) >>>>