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. Semi-Complicated Databinding Issue

Semi-Complicated Databinding Issue

Scheduled Pinned Locked Moved C#
helpwpfwcftutorialquestion
3 Posts 2 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.
  • D Offline
    D Offline
    Drew McGhie
    wrote on last edited by
    #1

    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?

    G 1 Reply Last reply
    0
    • D Drew McGhie

      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?

      G Offline
      G Offline
      GirishKB
      wrote on last edited by
      #2

      Can you publish your code snippet. That will help in better understanding of your problem .:)

      D 1 Reply Last reply
      0
      • G GirishKB

        Can you publish your code snippet. That will help in better understanding of your problem .:)

        D Offline
        D Offline
        Drew McGhie
        wrote on last edited by
        #3

        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.

        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