Semi-Complicated Databinding Issue
-
I'm having an issue with the changes made to combobox selections being pushed back to a datatable. Hopefully I'll be able to explain things enough to at least get some help. I have two comboboxes on a form. Each has its dataSource set to a pre-populated table in a dataset. Upon selection of a value in the first one, I change the DataTable.DefaultView.RowFilter on the second combobox's source table to filter the table and only display relevant selctions. I also have a table which is meant to save the values selected in those two comboboxes. I declare a BindingSource, and set its dataSource to a third table in the dataset. I DataBind the comboboxes' SelectedValue property to the appropriate columns in the 3rd datatable. Here's my issue. Upon selecting a value in the first combobox, and then hitting the button that calls .EndEdit on the binding source, only the first combobox's value is moved back into the datatable, and the new second combobox's value is not. I can select a value in the first, and then re-select the new filtered value, and that will result in a proper binding back to the datatable. I'm looking for assistance on how to tell the bindingsource to process the new filtered value in the second combobox, since the user has not actually changed the value itself. Any suggestions?
-
I'm having an issue with the changes made to combobox selections being pushed back to a datatable. Hopefully I'll be able to explain things enough to at least get some help. I have two comboboxes on a form. Each has its dataSource set to a pre-populated table in a dataset. Upon selection of a value in the first one, I change the DataTable.DefaultView.RowFilter on the second combobox's source table to filter the table and only display relevant selctions. I also have a table which is meant to save the values selected in those two comboboxes. I declare a BindingSource, and set its dataSource to a third table in the dataset. I DataBind the comboboxes' SelectedValue property to the appropriate columns in the 3rd datatable. Here's my issue. Upon selecting a value in the first combobox, and then hitting the button that calls .EndEdit on the binding source, only the first combobox's value is moved back into the datatable, and the new second combobox's value is not. I can select a value in the first, and then re-select the new filtered value, and that will result in a proper binding back to the datatable. I'm looking for assistance on how to tell the bindingsource to process the new filtered value in the second combobox, since the user has not actually changed the value itself. Any suggestions?
-
Can you publish your code snippet. That will help in better understanding of your problem .:)
prior to the form being shown, these two are called in this order, assume everything not declared is declared before.
public void LoadForm() { PlayerSource = new BindingSource(); //assign to prepopulated table PlayerSource.DataSource = myClient.PlayerList; TeamSource = new TeamSource(); //same deal TeamSource.DataSource = myClient.TeamList; //assigning of Player info to labels through databinding //databind player combobox uxcbPlayer.ValueMember = "PlayerID"; uxcbPlayer.DisplayMember = "PlayerFullName"; uxcbPlayer.DataSource = PlayerSource; //databind team combobox uxcbTeam.ValueMember = "TeamID"; uxcbTeam.DisplayMember = "TeamFullName"; uxcbTeam.DataSource = TeamSource; } public void LoadData() { CurrentPlayerSource = new BindingSource(); CurrentPlayerSource.DataSource = myClient.CurrentPlayer; uxcbTeam.DataBindings.Add("SelectedValue", TeamSource, "Team", false, DataSourceUpdateMode.OnValidation, ""); uxcbPlayer.DataBindings.Add("SelectedValue", TeamSource, "PlayerName", false, DataSourceUpdateMode.OnValidation, ""); }
In the Team.SelectedValueChanged event I call this funciton:public void FilterTeam () { if (uxcbTeam.SelectedValue != null) { if (PlayerSource != null) { PlayerSource.Filter = "Team = '" + uxcbTeam.Text + "'"; //uxcbBuilding.SelectedIndex = -1; //reset cbBuilding Selected Index } } }
Upon needing to save, I call CurrentPlayerSource.EndEdit(), and then deal with the data. The problem is that upon .EndEdit, the new value of the Player dropdown is not committed back to the database. Say if team A and Player A2 are selected initially, and the team is changed to team C, players C1-Cwhatever populate the second dropdown, C1 is shown initially, but on EndEdit, A2's value is put back in the datatable. If the user opens the player dropdown, and then selected the programatically-selected C1, then upon .EndEdit(), C1 is sent back, but I'm looking for a way to somehow "catch" the change on the second set and have the databindingsource (in this case, CurrentPlayerSource) catch the change.