473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 1158
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: BBFrost | last post by:
Win2000 ..Net 1.1 SP1 c# using Visual Studio Ok, I'm currently in a "knock down - drag out" tussle with the .Net 1.1 datagrid. I've come to realize that a 'block' of rows highlighted within...
2
by: scott | last post by:
Hi all, Iv got a slight problem with a datagrid and the ability to only display certain things in it. I have a Data grid which is connected to a data table. The data table is connected...
2
by: Alex | last post by:
Hi all, I'm writing a small web application which searches a database based on a date field, and populates a datagrid control with the results. The datagrid control has selection buttons added...
6
by: Erik H. | last post by:
Trying to connect to MySQL db on localhost, and populate datagrid from a dataset using code inline method. Getting the following compile error: Error Message: "CS0246: The type or namespace...
7
by: Joe | last post by:
Hi, I’m new to asp.net. I want to create an asp.net page that allows user to edit the data. I have pasted my code below. I am able to display the data in a datagrid. At the bottom of the page...
6
by: tshad | last post by:
I need to get to a status label I have on my footer section of my datalist. There is no event happening that would go to the footer. I am just doing some processing and want to update the label...
0
by: Greg | last post by:
I've made a datagrid multiline (for anyone interested, I used an adaptation of the code at http://64.78.52.104/FAQ/WinForms/FAQ_c44c.asp). This has introduced a very serious issue: the vertical...
1
by: dallasfreeman | last post by:
I'm looking at a quick way to get results that are displayed as rows to display as columns. I have three tables:- - The Questions for the survey - The Results of the survey (Columns are listed...
0
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.