ARTICLE

How to Iterate through the DataGrid

Posted by sailaja Articles | Visual Basic 2010 February 09, 2005
This article describes how to iterate through the datagrid
 
Reader Level:

Most of the cases we need to traverse through the DataGrid.

Here is the code snippet for that :

Private
Sub button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)

Dim cm As CurrencyManager = CType(Me.BindingContext(Me.dataGrid1.DataSource), CurrencyManager)
Dim rowCount As Integer
= cm.Count
'assumes datasource is a datatable
Dim colCount As Integer = (CType(Me.dataGrid1.DataSource, DataTable)).Columns.CountDim row As Integer
= 0
Do While
row < rowCount
Dim col As Integer
= 0
Do While
col < colCount
Dim cellValue As Object = Me
.dataGrid1(row, col)
Console.Write(cellValue.ToString() & " ")
col += 1
Loop
Console.WriteLine("")
row += 1
Loop
End Sub

Private cm As CurrencyManager = CType(Me.BindingContext(Me.dataGrid1.DataSource), CurrencyManager)
Private rowCount As Integer
= cm.Count
'assumes datasource is a datatable
Private colCount As Integer = (CType(Me
.dataGrid1.DataSource, DataTable)).Columns.Count
Dim row As Integer
= 0
Do While
row < rowCount
Dim col As Integer
= 0
Do While
col < colCount
Dim cellValue As Object = Me
.dataGrid1(row, col)
Console.Write(cellValue.ToString() & " ")
col += 1
Loop
Console.WriteLine("")
row += 1
Loop

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor