Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine number of rows in a datagrid

Status
Not open for further replies.

GeorgeDurkee

Programmer
Feb 22, 2000
47
0
0
US
I am using a data grid to contain a subset of data from an adodc recordset using the Parent/Child relationship to populate the datagrid.

Here is the sql statement that populates the recordset:
strsql = SHAPE {select PROJTITLE,PROCONTTYPE,PROJBILLMOC,PROJBILLRC,PROSTARTDATE,PROJKEY from PROJECTS where datepart('YYYY',[prostartdate]) = 2003 Order by PROJTITLE} AS ParentCMD APPEND ({select staffname as Employee,fk_staffkey,fkprojkey from PROJECTEFFORT,staff where fk_staffkey=staffkey Order by Staffname Asc} AS ChildCMD RELATE PROJKEY TO FKPROJKEY) AS ChildCMD

Here are the commands to populate the recordset and then the datagrid:
datPrimaryRS.RecordSource = strsql
datPrimaryRS.Refresh
Set grdDataGrid.DataSource = datPrimaryRS.Recordset("ChildCMD").UnderlyingValue


How can I determine how many rows are in the resultant datagrid so I can loop through the rows to generate a total for each of the 12 columns in the grid or do batch updates back to the database when the user leaves that parent record?

Thanks
 

You cannot loop through the rows in a data grid...except the visible rows (those currently seen on the screen).

Use the recordset object to loop. The data grid will follow the movements of the recordset. [/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
I haven't used datagrids, but I have used listviews. When I needed to know the number of records in the listview I used this code:

Dim intListViewCount as Integer
intListViewCount = lvwListViewName.ListItems.Count




The grid control also has an ApproxCount
which queries the data source for the count.

I hope this helped.

Good Luck!

John
[spidey] [americanflag] [unclesam]
 

GeorgeDurkee: so as I was saying, use your recordset object:

datPrimaryRS.RecordCount [/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Thanks for the updates

CClint - The datgrid contains a subset of the recordset. There are 300 records in the recordset, but only 5 in the datagrid, based on a key in the recordset. Using the recordset count as the base reports 300 records, not 5.

Mohrorless - There is no count function for the datagrid that I have been able to find, except for the number of columns. I just tried the Approx count again (I tried it yesterday and it didn't work) and it seems to do what I want.

thanks again.
 

May have beed to fast.

Are you using a DataGrid or a MSFlexHGrid? [/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 

mohrorless: good catch on that!
I must have been "sleeping"... [/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top