Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to determine the field a textbox is bound to
Message
 
À
29/10/2010 10:15:55
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 8.0
OS:
Vista
Network:
Windows XP
Database:
Jet/Access Engine
Application:
Desktop
Divers
Thread ID:
01487443
Message ID:
01487520
Vues:
48
Dear Bonnie,

Close, I guess.... but no cigar.

Let me try to clarify:

This is how I call the routine and define "cols"
    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
so, cols is really Me.XXXDataset.XXX.Columns is a DataColumnCollection, belonging to a datatable ... I think.

in my baseform I have :
    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
and 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 Sub
Now 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?)

I get the feeling from what I read in my frmXXX.designer.vb that the datasource of the "binding" is a dataset, whereas you seemed to assume that it should be a datatable or a dataview.

That is precisely the problem I guess, because the form generates a xxxdataset that and binds the controls to a datatable that belongs the xxxDataset and is called XXX and referred to as xxxDataset.xxx. And it's the latter that I would like get a hold of from my base class textbox.

Thanks for caring and shoot away ....

Marc

>Marc,
>
>I'm not 100% sure exactly what you're trying to get at, but I'll give it a shot. What I'm not clear about in your post is what "cols" is. Here's a snippet of code that I have used in my TextBox sub-class (sorry, it's C#, so I hope you can follow it):
>
>
>// 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;
>
>
>It appears that you're also talking about a sub-classed control, I hope I am correct in that assumption. Since your question appears to be about whatever this "cols" thing is, I'm not sure if the above helps or not.
>
>If not, perhaps you can rephrase your question or post some more code.
>
>~~Bonnie
>
>
>>I have found that
>>
>>Me.DataBindings.Item(0).BindingMemberInfo.BindingField
>>
>>
>>gives me the name of the field a control is bound to.
>>
>>
>>Dim o As DataColumn = cols(Me.DataBindings.Item(0).BindingMemberInfo.BindingField)
>>
>>
>>gets me the column, or the field that I am looking for.
>>
>>cols is passed to the method from the form's dataset.datatable (I guess).
>>
>>Is there a way for a textbox to let it's findform produce these (dataset.datatable).cols?

If things have the tendency to go your way, do not worry. It won't last. Jules Renard.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform