Getting only datagrid results?

  • Thread starter Thread starter Brett Romero
  • Start date Start date
B

Brett Romero

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
 
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
 
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
 
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
 
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
 
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
 
Back
Top