Instantiating a form's dataset

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to create a preview shot of a record being edited, so I want to
take the current state and pass it to a instance of a form I have. I've tried
to create a dataView and pass that, but it has been failing.

System.Data.DataRowView drvCurrent;
System.Data.DataView dvNew;
dvNew = new System.Data.DataView();
drvCurrent = (System.Data.DataRowView)this.ds1.Message;
dvNew.Table = this.ds1.Message;
dvNew.RowFilter="MessageID = '" +drvCurrent[0] +"'";
Form frmTemp = new frmPreview(dvNew);

I could iterate through the active controls, but the form takes care of
formatting based on the contents of the record it's reading.

Thanks in advance,

E.
 
Hi
why did it fail , what is the error message ?
did you create a construcor on your rmPreview class that take dataview
object as an input paramter, also you need to save that input param that
you get from the constructor in private dataview inside that class . if you
already have that please explain more what is the error that you get
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
The DataView was not being handled at all in the class, it just passed
through the try block as though it had an error and never processed (no error
message, just no results). Looking closer, the try block and class
constructor don't have a method to process it. Thanks for the reply,
Mohamoss, I should have seen it sooner.

E.
 
Esteban404,

Is ds1 a DataSet? If so, you have to pass the table in the data set to
the data view. You can't just cast a data set (or data table for that
matter) to a DataView. The view encapsulates the DataTable, not extends it.

Hope this helps.
 
Thanks for the reply. I know I'm going to have to write new constructors at
least.

I'm not great with the lingo of .NET yet. What I'm trying to pass is the
contents of the current record being edited (only) to the constructors of the
form used to display the contents of a datasource. This is to provide the
user a preview of their content. I thought there was a specific way to create
such a reference without passing individual member values, a list object or
something. I thought a dataset or dataview was the way to go. I won't be
shocked if I'm wrong.

E.

Nicholas Paldino said:
Esteban404,

Is ds1 a DataSet? If so, you have to pass the table in the data set to
the data view. You can't just cast a data set (or data table for that
matter) to a DataView. The view encapsulates the DataTable, not extends it.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Esteban404 said:
The DataView was not being handled at all in the class, it just passed
through the try block as though it had an error and never processed (no
error
message, just no results). Looking closer, the try block and class
constructor don't have a method to process it. Thanks for the reply,
Mohamoss, I should have seen it sooner.

E.
 
Esteban,

Yes, there is a way to do this. Basically, you want to look at the
BindingContext of the form that has the record that is being viewed. What
you can then do is set the data source on the new form to the same data
source of the old form (it must be the same thing, the DataSet or the
DataTable or the DataView, they can not be different). Once you do that,
you can set the Current property of the BindingContext of the new form to
the Current property of the binding context of the old form, and your
controls should be pointing at the same record (although they will keep
separate pointers, because they are separate binding contexts).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Esteban404 said:
Thanks for the reply. I know I'm going to have to write new constructors
at
least.

I'm not great with the lingo of .NET yet. What I'm trying to pass is the
contents of the current record being edited (only) to the constructors of
the
form used to display the contents of a datasource. This is to provide the
user a preview of their content. I thought there was a specific way to
create
such a reference without passing individual member values, a list object
or
something. I thought a dataset or dataview was the way to go. I won't be
shocked if I'm wrong.

E.

Nicholas Paldino said:
Esteban404,

Is ds1 a DataSet? If so, you have to pass the table in the data set
to
the data view. You can't just cast a data set (or data table for that
matter) to a DataView. The view encapsulates the DataTable, not extends
it.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Esteban404 said:
The DataView was not being handled at all in the class, it just passed
through the try block as though it had an error and never processed (no
error
message, just no results). Looking closer, the try block and class
constructor don't have a method to process it. Thanks for the reply,
Mohamoss, I should have seen it sooner.

E.

:

Hi
why did it fail , what is the error message ?
did you create a construcor on your rmPreview class that take
dataview
object as an input paramter, also you need to save that input param
that
you get from the constructor in private dataview inside that class .
if
you
already have that please explain more what is the error that you get
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
Thanks Nicholas! That's exactly what I was trying to communicate I want to do.

Do I pass them like this:
Form frmPreview = new frmDisplay(this.BindingContext[ds1,"Message"].Current,
false);

The two parameters are for the data and to not enable the timer, just wait
for a click to close the preview. I just need to build constructors for these
then.

I'll keep looking for information on bindingContext and parameters until I
get it right!

E.

Nicholas Paldino said:
Esteban,

Yes, there is a way to do this. Basically, you want to look at the
BindingContext of the form that has the record that is being viewed. What
you can then do is set the data source on the new form to the same data
source of the old form (it must be the same thing, the DataSet or the
DataTable or the DataView, they can not be different). Once you do that,
you can set the Current property of the BindingContext of the new form to
the Current property of the binding context of the old form, and your
controls should be pointing at the same record (although they will keep
separate pointers, because they are separate binding contexts).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Esteban404 said:
Thanks for the reply. I know I'm going to have to write new constructors
at
least.

I'm not great with the lingo of .NET yet. What I'm trying to pass is the
contents of the current record being edited (only) to the constructors of
the
form used to display the contents of a datasource. This is to provide the
user a preview of their content. I thought there was a specific way to
create
such a reference without passing individual member values, a list object
or
something. I thought a dataset or dataview was the way to go. I won't be
shocked if I'm wrong.

E.

Nicholas Paldino said:
Esteban404,

Is ds1 a DataSet? If so, you have to pass the table in the data set
to
the data view. You can't just cast a data set (or data table for that
matter) to a DataView. The view encapsulates the DataTable, not extends
it.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


The DataView was not being handled at all in the class, it just passed
through the try block as though it had an error and never processed (no
error
message, just no results). Looking closer, the try block and class
constructor don't have a method to process it. Thanks for the reply,
Mohamoss, I should have seen it sooner.

E.

:

Hi
why did it fail , what is the error message ?
did you create a construcor on your rmPreview class that take
dataview
object as an input paramter, also you need to save that input param
that
you get from the constructor in private dataview inside that class .
if
you
already have that please explain more what is the error that you get
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
Back
Top