Results 1 to 2 of 2

Thread: Help to load table to a textbox when selecting in combobox with connection to anothe

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2018
    Posts
    1

    Help to load table to a textbox when selecting in combobox with connection to anothe

    Well I have a combobox connected to a database, then I want that when selecting an item I upload another table to a textbox, for example:

    I have 2 table, Subject and credit, then I want that when selecting the subject, I load the credit in a textbox.

    Heee tried many ways but I can not do it, thanks!

    And forgive my bad English, thank you for the time given

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: Help to load table to a textbox when selecting in combobox with connection to ano

    Unless you have a reason not to, I would suggest that you execute a single query that joins the two database tables, so you can populate a single DataTable with all the data and then bind that to both controls. If you bind both controls then the TextBox will be populated automatically when you make the selection in the ComboBox. E.g.
    csharp Code:
    1. myComboBox.DisplayMember = "NameOfColumnToDisplayInComboBox";
    2. myComboBox.ValueMember = "NameOfPrimaryKeyColumn";
    3. myComboBox.DataSource = myDataTable
    4. ;
    5.  
    6. myTextBox.DataBindings.Add("Text", myDataTable, "NameOfColumnToDisplayInTextBox");

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width