Help with binding combo box and datarow column
-
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?
-
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?
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; } }
-
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?
I believe your friend's :) are called BindingContext and CurrencyManager, see the following article[^] Network integrated solutions
A practical use of the MVC pattern -
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?
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!!!