Solved

Number / Amount of Rows in Datagrid

Posted on 2004-09-16
8
191 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
ID: 12078267
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
ID: 12078289
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
ID: 12078293
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
ID: 12081650
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
ID: 12083939
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

785 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