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. Help with binding combo box and datarow column

Help with binding combo box and datarow column

Scheduled Pinned Locked Moved C#
questionwpfwcfhelptutorial
4 Posts 4 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.
  • M Offline
    M Offline
    Matthew Cuba
    wrote on last edited by
    #1

    Hello, I've got a combobox that needs to provide the following choices: choice1 choice2 choice3 I've also got a dataRow with some columns, one of them is called "choice". I want to do two things, and I believe it is possible to do but I don't quite know how to set this up. First, I want to make the "choice" column update to the selection made in the combobox. Additionally, I want to update the combobox to display the current value in the "choice" column, as it might have changed via another source - assume that there are two displays both providing the same controls and both pointing at the same dataRow. I'm wanting to keep this combobox "in sync" with the choice currently in the dataRow. How do I do this? Thanks, Matt

    It isn't enough to do well in life. One must do good when and where one can. Otherwise, what's the point?

    J Z S 3 Replies Last reply
    0
    • M Matthew Cuba

      Hello, I've got a combobox that needs to provide the following choices: choice1 choice2 choice3 I've also got a dataRow with some columns, one of them is called "choice". I want to do two things, and I believe it is possible to do but I don't quite know how to set this up. First, I want to make the "choice" column update to the selection made in the combobox. Additionally, I want to update the combobox to display the current value in the "choice" column, as it might have changed via another source - assume that there are two displays both providing the same controls and both pointing at the same dataRow. I'm wanting to keep this combobox "in sync" with the choice currently in the dataRow. How do I do this? Thanks, Matt

      It isn't enough to do well in life. One must do good when and where one can. Otherwise, what's the point?

      J Offline
      J Offline
      joon vh
      wrote on last edited by
      #2

      For the datarow to change when you select something in the combobox, it's easy, just add some code to the ComboBox.SelectedIndexChanged event.

      table.rows[x][y].value = comboBox1.Value
      

      but to do it the other way around, you either have to use events too (f.e. DataTable.RowChanged...) or you can use a timer that checks the datasource for change and updates the combobox.


      Visual Studio can't evaluate this, can you? public object moo { __get { return moo; } __set { moo = value; } }

      1 Reply Last reply
      0
      • M Matthew Cuba

        Hello, I've got a combobox that needs to provide the following choices: choice1 choice2 choice3 I've also got a dataRow with some columns, one of them is called "choice". I want to do two things, and I believe it is possible to do but I don't quite know how to set this up. First, I want to make the "choice" column update to the selection made in the combobox. Additionally, I want to update the combobox to display the current value in the "choice" column, as it might have changed via another source - assume that there are two displays both providing the same controls and both pointing at the same dataRow. I'm wanting to keep this combobox "in sync" with the choice currently in the dataRow. How do I do this? Thanks, Matt

        It isn't enough to do well in life. One must do good when and where one can. Otherwise, what's the point?

        Z Offline
        Z Offline
        Zoltan Balazs
        wrote on last edited by
        #3

        I believe your friend's :) are called BindingContext and CurrencyManager, see the following article[^] Network integrated solutions
        A practical use of the MVC pattern

        1 Reply Last reply
        0
        • M Matthew Cuba

          Hello, I've got a combobox that needs to provide the following choices: choice1 choice2 choice3 I've also got a dataRow with some columns, one of them is called "choice". I want to do two things, and I believe it is possible to do but I don't quite know how to set this up. First, I want to make the "choice" column update to the selection made in the combobox. Additionally, I want to update the combobox to display the current value in the "choice" column, as it might have changed via another source - assume that there are two displays both providing the same controls and both pointing at the same dataRow. I'm wanting to keep this combobox "in sync" with the choice currently in the dataRow. How do I do this? Thanks, Matt

          It isn't enough to do well in life. One must do good when and where one can. Otherwise, what's the point?

          S Offline
          S Offline
          Seishin
          wrote on last edited by
          #4

          I suppouse the datarow is in a datatable.. if you have a datatable then you can bind it using BindingSource. set the DataSource of the BindingSource object to the table object. then set the DataSource of the ComboBox object to the BindingSource object and the DataMember and DisplayMember to proper column names from the table. someBindingSource = new BindingSource(); someBindingSource.DataMember = "tableName"; // if the table is in a dataset someBindingSource.DataSource = someDataTable; // or DataSet someComboBox.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", someBindingSource, "Column2name", true)); someComboBox.DataSource = someBindingSource; someComboBox.DisplayMember = "Column1name"; someComboBox.ValueMember = "Column2name"; someComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;

          life is study!!!

          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