Solved

Number / Amount of Rows in Datagrid

Posted on 2004-09-16
8
183 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

21 Experts available now in Live!

Get 1:1 Help Now