Solved

Number / Amount of Rows in Datagrid

Posted on 2004-09-16
8
171 Views
Last Modified: 2010-04-23
Hi all,

How can I get in a windows form the number of rows in a datagrid. I don´t  see any Count of EOF thing to for the datagrid... Who can help me out?
0
Comment
Question by:GNTK
  • 3
8 Comments
 
LVL 22

Accepted Solution

by:
Snarf0001 earned 250 total points
Comment Utility
You can't directly from the datagrid.

You need to count the rows from the datasource bound to the grid. ie:

   CType(Datagrid.DataSource, DataTable).Rows.Count

0
 
LVL 22

Expert Comment

by:Snarf0001
Comment Utility
As a side note, if you're looking for EOF, I'd imagine you're looking to loop through items in the grid and do some sort of processing.
Keep in mind, that in the windows forms, as soon as data in the grid is modified, so is the bound datatable/dataset.

If you want to loop through items for processing or any other manipulation, it's faster just to loop through the datasource as opposed to the grid itself.
0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 250 total points
Comment Utility
The DataGrid simply displays data...it doesn't house it.  You need to query the underlying data source and ask it how many rows there are.  The DataSource() property will give you a reference to the underlying data structure which can be:
    A DataTable
    A DataView
    A DataSet
    A DataViewManager
    Any component that implements the IListSource interface
    Any component that implements the IList interface

Then you can use the appropriate method or property for that source to determine the number of rows from that source.

Regards,

Idle_Mind
0
 
LVL 2

Expert Comment

by:ahmadfuwad
Comment Utility
you can use following property for counting row in datagrid

Dim rowcount As Integer
rowcount = Me.DataGrid1.VisibleRowCount()
0
 
LVL 22

Expert Comment

by:Snarf0001
Comment Utility
That's not what the command is intended for.

VisibleRowCount will only return the number of rows currently displayed on the screen.  If there's scrolling involved or anything of that nature, any rows not currently visible in the window will be excluded from the count.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now