How do you get a list of Datagrid names?

  • Thread starter Thread starter KC
  • Start date Start date
K

KC

How can I get a list of DataGrids used in my application? I could obviously
do this manually at design time, but I don't want to have to update the
list.
 
How can I get a list of DataGrids used in my application? I could obviously
do this manually at design time, but I don't want to have to update the
list.

For Each c As Control In Controls
If TypeOf c Is DataGrid Then
' Add the name to your array
End If
Next
 
Thank you. That helped a lot. But that example I've found assumes all my
datagrids are in the top 'Me' form. There's no easy way to get ALL the
controls in my app is there? I've got my stuff in panels in tabcontrols in
whatever....

Or will I just have to point it to the right subcontrols?

Ken
 
Hi,


Use recursion.

CheckForGrid(Me.Controls)



Private Sub CheckForGrid(ByVal ctrls As Control.ControlCollection)

For Each ctrl As Control In ctrls

If TypeOf ctrl Is DataGrid Then

Trace.WriteLine(DirectCast(ctrl, DataGrid).Name)

End If

CheckForGrid(ctrl.Controls)

Next

End Sub



Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top