?
Solved

Number / Amount of Rows in Datagrid

Posted on 2004-09-16
8
Medium Priority
?
215 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
8 Comments
 
LVL 23

Accepted Solution

by:
Snarf0001 earned 1000 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 23

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 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 1000 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 23

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month12 days, 13 hours left to enroll

777 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