Derived Dataset and Datagrid binding

G

Guest

Hello.
For simplicity sake, I wanted to use a dataset as my business object, but
because I needed to implement a lot of business logic, I've just derived my
classes from the typed dataset (and datatable and datarow using ADO.NET
Dataset builder by Shawn Wildermuth).
Everything works great, but after binding my objects to a datagrid, I need
to change some small things for each row in the grid, so I'm implementing
Datagrid's OnItemCommand delegate which returns me DataItem inside the
e.Item.
The thing is, for some unknown to me reason, the DataItem is of type
DataRowView, and I can't cast it neither to my object nor to DataRow.
What can I do? How can I get the original object it was bound (at least I
think it was) to?
Thanks in advance.
 
M

Miha Markic [MVP C#]

Hi Vlad,

Yes, you always bind dataview (a wrapper around DataTable) and not
datatable.
Try with DataRowView.Row to get to the DataRow.
 
G

Guest

Thanks a lot, works like a magic.
Now a have other problems, with my approach, but I think I'll overcome them.
Thanks again.

Vlad.

Miha Markic said:
Hi Vlad,

Yes, you always bind dataview (a wrapper around DataTable) and not
datatable.
Try with DataRowView.Row to get to the DataRow.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com


Vlad A. said:
Hello.
For simplicity sake, I wanted to use a dataset as my business object, but
because I needed to implement a lot of business logic, I've just derived
my
classes from the typed dataset (and datatable and datarow using ADO.NET
Dataset builder by Shawn Wildermuth).
Everything works great, but after binding my objects to a datagrid, I need
to change some small things for each row in the grid, so I'm implementing
Datagrid's OnItemCommand delegate which returns me DataItem inside the
e.Item.
The thing is, for some unknown to me reason, the DataItem is of type
DataRowView, and I can't cast it neither to my object nor to DataRow.
What can I do? How can I get the original object it was bound (at least I
think it was) to?
Thanks in advance.
 
G

Guest

Is there a way to bind the datagrid to my actual object, and not the derived
datatable?
I have a feeling that the dataset.Bind checks if the object was derived from
a dataset or a datatable and if so, gets the default view.

Thanks again,
Vlad.

Miha Markic said:
Hi Vlad,

Yes, you always bind dataview (a wrapper around DataTable) and not
datatable.
Try with DataRowView.Row to get to the DataRow.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com


Vlad A. said:
Hello.
For simplicity sake, I wanted to use a dataset as my business object, but
because I needed to implement a lot of business logic, I've just derived
my
classes from the typed dataset (and datatable and datarow using ADO.NET
Dataset builder by Shawn Wildermuth).
Everything works great, but after binding my objects to a datagrid, I need
to change some small things for each row in the grid, so I'm implementing
Datagrid's OnItemCommand delegate which returns me DataItem inside the
e.Item.
The thing is, for some unknown to me reason, the DataItem is of type
DataRowView, and I can't cast it neither to my object nor to DataRow.
What can I do? How can I get the original object it was bound (at least I
think it was) to?
Thanks in advance.
 
M

Miha Markic [MVP C#]

Vlad Azarkhin said:
Is there a way to bind the datagrid to my actual object, and not the
derived
datatable?
I have a feeling that the dataset.Bind checks if the object was derived
from
a dataset or a datatable and if so, gets the default view.

AFAIK DataTable is never bound directly....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top