• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

Number / Amount of Rows in Datagrid

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
GNTK
Asked:
GNTK
  • 3
2 Solutions
 
Snarf0001Commented:
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
 
Snarf0001Commented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
ahmadfuwadCommented:
you can use following property for counting row in datagrid

Dim rowcount As Integer
rowcount = Me.DataGrid1.VisibleRowCount()
0
 
Snarf0001Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now