Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Multiple DataBindings to the same control

Multiple DataBindings to the same control

Scheduled Pinned Locked Moved C#
questionhelpannouncementcareer
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Adam Turner
    wrote on last edited by
    #1

    I think I have come across a fairly common situation but I cant find any help with this. I have a simple form with 2 controls. A text box (Employee's Name) and a combo box (Employee's Job Title). I have a DataTable that I have tied both the text box and combo box to. Changing positions using the CurrencyManager works fine and everything is good. But now I want to populate the combo-box with a list of all available jobs. I want to be able to select a item from the list and have it update the appropriate row in my DataTable as would an edit within the text box. I have the following code, but I get un-expected results. DataTable jobs = new DataTable("Jobs"); jobs.Columns.Add("Job", typeof(string)); jobs.Rows.Add(new object[] {"Software Engineer"}); jobs.Rows.Add(new object[] {"Project Manager"}); jobs.Rows.Add(new object[] {"Tester"}); jobs.Rows.Add(new object[] {"Documenter"}); jobs.Rows.Add(new object[] {"Project Lead"}); cboJob.DataSource = t; cboJob.DisplayMember = "Job"; DataTable namesAndJobs = new DataTable("NamesAndJobs"); namesAndJobs.Columns.Add("Name", typeof(string)); namesAndJobs.Columns.Add("Job", typeof(string)); namesAndJobs.Rows.Add(new object[] {"Bob", "Project Lead"}); namesAndJobs.Rows.Add(new object[] {"Mark", "Documenter"}); namesAndJobs.Rows.Add(new object[] {"Henry", "Project Manager"}); txtName.DataBindings.Add("Text", namesAndJobs, "Name"); cboJob.DataBindings.Add("Text", namesAndJobs, "Job"); Can what I want to do, even be done? If not, what is the purpose of allowing multiple DataBindings to the same control? "I am so smart. S-M-R-T. I mean, S-M-A-R-T" - Homer

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups