Testing for no controls collection

T

Tina

I have a DataGrid Item from the header row of a 1.1 DataGrid. I got it by
saying...

Dim HeaderItem As DataGridItem = mygrid.Controls(0).Controls(0)

Now I'm looping through the Header item cells but first testing each cell as
so....

If HeaderItem.Cells(i).Controls(0) Is Nothing Then ...

the reason for this test is that sometimes the heading text is in
HeaderItem.Cells(i).text (in the case of a normal heading) and sometimes
it's inside a LinkButton (in the case of a sort enabled column).

My problem is that this "is Nothing" test throws an exception if the cell
being tested has no Controls collection. So testing for Is Nothing doesn't
work because the test gets an index out of bounds exception.

How can I test for the lack of the controls collection without getting an
exception.

(I don't want to put this into a try-catch block for performance reasons)
(also please understand that I am in a method that is getting passed this
datagrid - not in any event while it is being built)

Thanks,
T
 
G

GaryDean

hey Tina,
you should be able to test for Headeritem.Cells(i).Controls.count.

Sounds like your working on PrintGrid!

Gary
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top