C#-app : Write to one dataset causes another dataset to revert to previous form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mydogisbox
    New Member
    • May 2007
    • 7

    C#-app : Write to one dataset causes another dataset to revert to previous form

    I have two datasets. One dataset table from dataset1 is bound to a list box. On selection in the list box dataset2 has 9 tables that are populated from the database. these tables are then data-bound to 9 combo boxes. Following selection of items in the combo boxes and the click of a button, the results are then manually written back to the first table in dataset1. The problem that I am having is that after the selection in the first combo box is written to the table, all of the combo boxes revert to their previous selection. Following are the sections of code which I think should be needed:

    //create the tables in the second dataset
    cbLineupPositio n[i-1].DisplayMember = "PositionNa me";
    cbLineupPositio n[i-1].ValueMember = "PositionID ";
    cbLineupPositio n[i-1].DataSource =DataSet2.Table s["LineupPosition "+i.ToStrin g()];


    DataSet.Tables["teams"].Rows[lbTeams.Selecte dIndex]["One"]
    =cbLineupName[0].SelectedValue;
    DataSet.Tables["teams"].Rows[lbTeams.Selecte dIndex]["Two"] =
    cbLineupName[1].SelectedValue;
    DataSet.Tables["teams"].Rows[lbTeams.Selecte dIndex]["Three"] =
    cbLineupName[2].SelectedValue;
    DataSet.Tables["teams"].Rows[lbTeams.Selecte dIndex]["Four"] =
    cbLineupName[3].SelectedValue;
    DataSet.Tables["teams"].Rows[lbTeams.Selecte dIndex]["Five"] =
    cbLineupName[4].SelectedValue;
    DataSet.Tables["teams"].Rows[lbTeams.Selecte dIndex]["Six"] =
    cbLineupName[5].SelectedValue;
    DataSet.Tables["teams"].Rows[lbTeams.Selecte dIndex]["Seven"] =
    cbLineupName[6].SelectedValue;
    DataSet.Tables["teams"].Rows[lbTeams.Selecte dIndex]["Eight"] =
    cbLineupName[7].SelectedValue;
    DataSet.Tables["teams"].Rows[lbTeams.Selecte dIndex]["Nine"] =
    cbLineupName[8].SelectedValue;
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    My guess would be that since you are writing to the dataset that populates the first listbox, it is re-binding the listbox to the newly effected dataset. And the selection_chang e event gets fired on a databind, which in turn fires off the "populate all my combo boxes" dealy.

    Comment

    • mydogisbox
      New Member
      • May 2007
      • 7

      #3
      Thanks a lot for the quick reply. I will look at that possibility.

      Comment

      • mydogisbox
        New Member
        • May 2007
        • 7

        #4
        On brief inspection that appears to be exactly what is happening. Thanks a lot. :-)

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          For what it's worth, I usually don't do direct editing of my dataset's.
          I'll have a like PopulateClients () function who's job it is to retrieve the dataset and populate my listbox/combobox/datagridview.
          Then I will do my manipulating, and when i'm all done and want to refresh, I will call the Populate function again.

          If you want to directly edit the datasets, you could try:
          retrieving your dataset.
          make a CLONE/COPY of it.
          use one to populate listbox
          use other to work with the combo boxes and changing of data with it
          Then go back to stop and make a copy of the dataset with new data and populate the listbox with a copy of it and manipulate the other.
          I think that should work?

          Comment

          • mydogisbox
            New Member
            • May 2007
            • 7

            #6
            Originally posted by Plater
            If you want to directly edit the datasets, you could try:
            retrieving your dataset.
            make a CLONE/COPY of it.
            use one to populate listbox
            use other to work with the combo boxes and changing of data with it
            Then go back to stop and make a copy of the dataset with new data and populate the listbox with a copy of it and manipulate the other.
            I think that should work?
            I would think that would work. Is there a simple way to clone a dataset?

            Added: It turns out I can be much lazier than that. I simply have a bool that indicates whether or not I'm currently saving and if so, I make the SelectedIndexCh anged event do nothing.

            Thanks again for your help.

            Comment

            Working...