Textbox databinding to class object nested property


  • Hello,

    I'm trying to bind a textbox.text to a class object property but I am failing to do so.

    I made a simple representation of the code. The first class is a class I created, the second is from a Interop file from Autodesk Inventor.

    What I would like to do is bind my class DisplayedDocument it's Value to a textbox.text property.

    Class DisplayedDocument
        Public Property Title As Inventor.Property
        Public Property Subject As Inventor.Property
    End Class
    Class Inventor.Property
        Public Property Value As String
        Public Property Expression As String
    End Class

    My attempt

    TextBox1.DataBindings.Add("Text", _DisplayDocument.Subject, "Value")

    Whats wrong? Is this a bad workflow? Please advise :D

    Tuesday, March 28, 2017 11:52 AM

All replies

  • See if this is what you are after

    Class DisplayedDocument
        Inherits Inventor
        Public Property Title As String
        Public Property Subject As String
    End Class
    Class Inventor
        Public Property Value As String
        Public Property Expression As String
    End Class
    Private sampleItem As New DisplayedDocument
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        sampleItem.Title = "the title"
        sampleItem.Value = "Some value"
        TextBox1.DataBindings.Add("text", sampleItem, "value")
    End Sub

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, March 28, 2017 12:29 PM
  • Your databinding looks correct, but the Inventor.Property class is not correct; you can't have a period in the class name. Perhaps you mean that the Property class is in an Inventor namespace:

    Namespace Inventor
        Public Class [Property]
            Public Property Value As String
            Public Property Expression As String
        End Class
    End Namespace

    That would make the DisplayedDocument property definitions correct.

    If that is what you actually have, then your data binding should work.  When you said you were "failing to do so", what didn't work?  If the problem actually has to do with changing the Inventor.Property.Value and not seeing that change reflected in the textbox, then that issue has to do with binding managers and the fact that Inventor.Property does not implement INotifyPropertyChanged so you have to manually refresh the display.

    What is the actual problem?

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Tuesday, March 28, 2017 1:09 PM