Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagridview Looping Through Multiples

Status
Not open for further replies.

kennedymr2

Programmer
May 23, 2001
594
AU
I have a form with 6 datagridview controls ie datagridview1 datagridview2 etc

I need to loop through the 6 controls to set columnscount etc

rather than doing 6 seperate loops , is there a way eg

for ll= 1 to 6

With datagridview & str(ll)

???.columnscount=12

end with

next ll


Really appreciate some help

Regards Kennedymr2
 
I don't have VS running on this machine, so I won't post any sample code, just a "from memory" bit of code.

However if you have a look at the form's Controls property you can use something like:

[tt]
for a as integer = 0 to me.controls.count - 1
if typeof me.controls(a) is datagridview then
dim dgv as datagridview = ctype(me.controls(a), datagridview)
'check the name property here if you need to i.e dgv.name
messagebox.show(dgv.name & " has " & dgv.columns.count.tostring & "columns") '*** see below
end if
next
[/tt]

*** I can't remember whether the count property is dgv.columns.count or dgv.columncount or something similar

Hope this helps
 
softhemc

Really appreciate the help it worked fine on a normal page

But i now find the the page i am trying to process is a TABPAGE

???How do i get the routine to work on a tabpage ?????

Appreciate some help if you have time


Regards Kennedymr2

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top