Binding controls to DataSet on other Form

  • Thread starter Thread starter Jos 78
  • Start date Start date
J

Jos 78

I have been a Delphi developer for some years now and am currently learning
C#.NET. I would like your opinion on the following:

Suppose I have Form1 with a read-only DataGrid component on it which
contains a list of Customers. Now I would like to be able to doubleclick on
the grid to open a second form (Form2), which would enable me to edit the
selected customer's name, phone etc.

Now the problem is I can't seem to bind the TextBoxes on Form2 to the
DataSet on Form1 (which was the way it's done in Delphi). Can anyone
explain to me the easiest way to do this in dotNET?

Should I create a new DataSet on Form2, and merge things from one DataSet
into the other? This seems a little awkward as I would be copying an entire
table just to edit one row.

All help greatly appreciated!
 
Hi
since form one calls form two then (form one holds a refernce to from two
and all its controls but not the other way around) .
in your case one thing you can do , is to overload the constructor of
form2 to make it take an input reference pramater of type dataset , then
pass to it the dataset of from one ( this way you would have a refence to
the dataset of from one in form2)
so
instead of
Form2 the_other_one = new Form2();
make it
Form2 the_other_one = new Form2(ref The_dataset);
of course you need to have a private member in form2 of type dataset , also
you need to write that constructor in form2 that take that refernce and
keep it in form2 set
hope that was clear
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
Back
Top