none
TextBox bound to datatable column RRS feed

  • Question

  • Hi

    By designer I bind several  Textbox.text to several datacolumns

    Now during control validating I need to get the datacolumn to wich each textbox is bound in order to get both proposed and original value.

    Which is the vb.net syntax ?

    Wednesday, January 16, 2019 5:08 PM

Answers

  • I hadn't done this until yesterday in C#, here is a translation from C# to VB.NET where textbox is the current TextBox in question.

    CType(textbox, TextBox).DataBindings(0).BindingMemberInfo.BindingField

    Properties for BindingMemberInfo

    I was using this to create a SQL query to an Oracle database table.

    var bindingFieldName = System.Text.RegularExpressions
        .Regex.Replace(((TextBox)textbox)
            .DataBindings[0].BindingMemberInfo.BindingField, @"[\d-]", "");
    
    var value = ((TextBox)textbox).Text;
    resultsTextBox.Text = $"OCS_DB_FIELD_NAME LIKE '%{bindingFieldName}%' AND OCS_LANG_CODE = '{tR_LANGUAGE_CODETextBox.Text}'";
    


    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

    • Marked as answer by Claudio111 Wednesday, January 16, 2019 7:29 PM
    Wednesday, January 16, 2019 6:41 PM
    Moderator

All replies

  • I hadn't done this until yesterday in C#, here is a translation from C# to VB.NET where textbox is the current TextBox in question.

    CType(textbox, TextBox).DataBindings(0).BindingMemberInfo.BindingField

    Properties for BindingMemberInfo

    I was using this to create a SQL query to an Oracle database table.

    var bindingFieldName = System.Text.RegularExpressions
        .Regex.Replace(((TextBox)textbox)
            .DataBindings[0].BindingMemberInfo.BindingField, @"[\d-]", "");
    
    var value = ((TextBox)textbox).Text;
    resultsTextBox.Text = $"OCS_DB_FIELD_NAME LIKE '%{bindingFieldName}%' AND OCS_LANG_CODE = '{tR_LANGUAGE_CODETextBox.Text}'";
    


    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

    • Marked as answer by Claudio111 Wednesday, January 16, 2019 7:29 PM
    Wednesday, January 16, 2019 6:41 PM
    Moderator
  • It works perfectly.

    Just one question . What does the (0) mean for DataBinding(0)



    • Edited by Claudio111 Wednesday, January 16, 2019 7:08 PM
    Wednesday, January 16, 2019 6:58 PM
  • It works perctly.

    Just one questtion . Whatdoes the (0) mean for DataBinding(0)


    DataBindings is a collection of bindings

    https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.controlbindingscollection?view=netframework-4.7.2


    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

    Wednesday, January 16, 2019 7:08 PM
    Moderator
  • OK. So if the textbox has two properties bound to objects properties is better to use control's property name to get the source for each property, like :

    CType(textbox, TextBox).DataBindings("Text").BindingMemberInfo.BindingField

    or

    CType(textbox, TextBox).DataBindings("Tag").BindingMemberInfo.BindingField

    Wednesday, January 16, 2019 7:20 PM
  • OK. So if the textbox has two properties bound to objects properties is better to use control's property name to get the source for each property, like :

    CType(textbox, TextBox).DataBindings("Text").BindingMemberInfo.BindingField

    or

    CType(textbox, TextBox).DataBindings("Tag").BindingMemberInfo.BindingField

    Either is fine.

    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

    Wednesday, January 16, 2019 7:24 PM
    Moderator