471,317 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,317 software developers and data experts.

Getting only datagrid results?

I've created a custom datagrid and would like to get only entries
displaying in the grid. The datasource may be a table or dataview. So
I check for this in the custom datagrid class:

if (this.DataSource.GetType().FullName.Equals("System .Data.DataTable"))
dt = (DataTable)this.DataSource;
else if
(this.DataSource.GetType().FullName.Equals("System .Data.DataView"))
dt = ((DataView)this.DataSource).Table;

The problem is I get the entire dataset and not only what is displayed
in the grid. For example, if a dataview has restricted a set from 12
to 4 rows, I get 12 rows. How do I get only the 4 displayed in the
grid?

Thanks,
Brett

Feb 14 '06 #1
7 1101
Brett,
Is there any reason why you can't get the filtered data out of the Dataview
itself?
This should be relatively easy, DataView has a collection of Items that are
DataRowView instances.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Brett Romero" wrote:
I've created a custom datagrid and would like to get only entries
displaying in the grid. The datasource may be a table or dataview. So
I check for this in the custom datagrid class:

if (this.DataSource.GetType().FullName.Equals("System .Data.DataTable"))
dt = (DataTable)this.DataSource;
else if
(this.DataSource.GetType().FullName.Equals("System .Data.DataView"))
dt = ((DataView)this.DataSource).Table;

The problem is I get the entire dataset and not only what is displayed
in the grid. For example, if a dataview has restricted a set from 12
to 4 rows, I get 12 rows. How do I get only the 4 displayed in the
grid?

Thanks,
Brett

Feb 14 '06 #2
How do I get that from inside the datagrid class? That's my question.
It has to be done in that class since the custom datagrid is handling
all of this. I'm making it part of the datagrid's functionality.

Thanks,
Brett

Feb 14 '06 #3
Brett,
when you do this:

(this.DataSource.GetType().FullName.Equals("System .Data.DataView"))
dt = ((DataView)this.DataSource).Table;

what you are doing is casting the **entire** DataTable to a DataView. Don't
you want something like "CurrentView" - which should only have the 4 rows?

maybe you can do something like:

DataView dv = this.DataSource as DataView

Just some ideas.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Brett Romero" wrote:
How do I get that from inside the datagrid class? That's my question.
It has to be done in that class since the custom datagrid is handling
all of this. I'm making it part of the datagrid's functionality.

Thanks,
Brett

Feb 14 '06 #4
DataView dv = this.DataSource as DataView

leaves me with a null dv. Also, I don't think there is a "CurrentView"
property. At least I can't find it. Good thoughts though.

Thanks,
Brett

Feb 14 '06 #5
After doing the check, this works:

dt.DefaultView.Table.Rows

Feb 14 '06 #6
Yup! Knew you would get it.
:-)
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Brett Romero" wrote:
After doing the check, this works:

dt.DefaultView.Table.Rows

Feb 14 '06 #7
Actually, that isn't working either. The rows I want are in
dt.DefaultView but I don't know how to get at them.

Brett

Feb 15 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Joe | last post: by
6 posts views Thread by tshad | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.