Passing DataSet between forms

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alintt
    New Member
    • Jul 2010
    • 1

    #1

    Passing DataSet between forms

    Hi,

    I searched this forum but not found a answer to fit my needs. The problem is: I have 2 forms and one dataset on the parent form who fill a DataGridView. I've passed the dataset to the child form (through a constructor), but now I need the data to be sent back to parent form. The DataSet on the child had some rows removed or added.

    Code:
    DataSet _dSet;
    //..........
    public Child(DataSet dSet)
            {
                InitializeComponent();
                _dSet = dSet.Copy();
            }
    If i put _dSet = dSet; then my DataSet on the parent is modifying when I delete or add a row (in real time). So when I want to close the child form whitout any modification, the DataSet on parent doesn't change back to the original one.

    And on the parent

    Code:
    DataSet dSet;
    //..............
    private void childButton_Click(object sender, EventArgs e)
            {
                Child child= new Child(dSet);
                //.......
            }
    So the final question is how do I make the Dataset on the parent to not change IF i close the child form (from X) and on the other hant to change (with the new one) IF I press OK Button.

    Thank you.
  • shaahin
    New Member
    • Jul 2010
    • 11

    #2
    Hi
    Define a dataset property in ur form.
    and get it from another form
    like a valuable.
    modifier should be public.
    good luck

    Comment

    • GaryTexmo
      Recognized Expert Top Contributor
      • Jul 2009
      • 1501

      #3
      I disagree, Shaahin. You shouldn't just make a member variable public to expose access.

      One option is to write a property for it. This allows you to control access. For something like a data set, you typically want get access only. This still lets you change the contents of the dataset, but it doesn't allow the destruction of the dataset from an external source (ie, another class).

      Here's an MSDN page on properties...
      http://msdn.microsoft.com/en-us/libr...8VS.80%29.aspx

      Comment

      Working...