We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to loop through all cell of a DataGrid in VB.net

I found some code I liked very much in ASP.net. I'm trying to modify it so it works with VB.NET. No luck so far. There is no Items property of the grid. Please help. Any other idea will help. Thank you! Private Sub SetHierarchical(ByVal bExpanded As Boolean) Dim iCount As Int32 For iCount = 0 To dgValues.Items.Count - 1 'set the bg colour of the Customer and Order rows and the plus minus cells If dgValues.Items(iCount).Cells(1).Text <> " " Then dgValues.Items(iCount).BackColor = System.Drawing.Color.Wheat dgValues.Items(iCount).Cells(0).BackColor = System.Drawing.Color.Tan End If If dgValues.Items(iCount).Cells(3).Text <> " " Then dgValues.Items(iCount).BackColor = System.Drawing.Color.AntiqueWhite dgValues.Items(iCount).Cells(2).BackColor = System.Drawing.Color.Tan End If 'set the bg colour of the total rows If dgValues.Items(iCount).Cells(4).Text = "Customer Total" Then _ dgValues.Items(iCount).BackColor = System.Drawing.Color.AntiqueWhite If bExpanded Then 'hide + on Test all rows where there is not an expandable node If dgValues.Items(iCount).Cells(3).Text = " " Then dgValues.Items(iCount).Cells(2).Controls(0).Visible = False Else 'set the minus sign CType(dgValues.Items(iCount).Cells(2).Controls(0), LinkButton).Text = "-" CType(dgValues.Items(iCount).Cells(2).Controls(0), LinkButton).CssClass = "PlusMinus" End If 'hide + on all Collection rows where there is not an expandable node If dgValues.Items(iCount).Cells(1).Text = " " Then dgValues.Items(iCount).Cells(0).Controls(0).Visible = False Else 'set the minus sign CType(dgValues.Items(iCount).Cells(0).Controls(0), LinkButton).Text = "-" End If Else 'hide + on all Order rows where there is not an expandable node If dgValues.Items(iCount).Cells(3).Text = " " Then dgValues.Items(iCount).Cells(2).Controls(0).Visible = False Else 'set the plus sign CType(dgValues.Items(iCount).Cells(2).Controls(0), LinkButton).Text = "+" CType(dgValues.Items(iCount).Cells(2).Controls(0), LinkButton).CssClass = "PlusMinus" End If 'hide + on all Customer rows where there is not an expandable node If dgValues.Items(iCount).Cells(1).Text = " " Then dgValues.Items(iCount).Cells(0).Controls(0).Visible = False Else 'set the plus sign CType(dgValues.Items(iCount).Cells(0).Controls(0), LinkButton).Text = "+" CType(dgValues.Items(iCount).Cells(0).Controls(0), LinkButton).CssClass = "PlusMinus" End If 'hide all child nodes and rows of the root nodes If dgValues.Items(iCount).Cells(1).Text = " " Then dgValues.Items(iCount).Visible = < FONT color = #0000ff > False End If Next End Sub

Loader.
Live Chat Icon For mobile
Up arrow icon