Derived Dataset and Datagrid binding

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
Hi Vlad,

Yes, you always bind dataview (a wrapper around DataTable) and not
datatable.
Try with DataRowView.Row to get to the DataRow.
 
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.
 
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.
 
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....
 
Back
Top