473,472 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Testing for no controls collection

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
Oct 13 '06 #1
1 1127
hey Tina,
you should be able to test for Headeritem.Cells(i).Controls.count.

Sounds like your working on PrintGrid!

Gary
"Tina" <Ti**********@nospamexcite.comwrote in message
news:Ov**************@TK2MSFTNGP02.phx.gbl...
>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

Oct 13 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
2
by: MFRASER | last post by:
How do I loop through a collection of controls testing to see if a certain control type already exists in the collection. //this doesn't work foreach(System.Windows.Forms.Control aControl in...
9
by: Merlin | last post by:
Hi, My code below doesn't work does anyone have any pointers? All my controls are programically added. Dim i As Int16 For i = 0 To Me.Controls.Count - 1 If Me.Controls(i).Name <>...
66
by: Cor | last post by:
Hi, I start a new thread about a discussion from yesterday (or for some of us this morning). It was a not so nice discussion about dynamically removing controls from a panel or what ever. It...
6
by: Peter Zolja | last post by:
Hi, I'm building a webcontrol that contains a dynamic list of other controls. My problem is that when I add or remove an item the synchronization between the ViewState and the Controls...
15
by: Arpan | last post by:
Consider the following code which retrieves data from a SQL Server 2005 DB table & displays it in a DataGrid: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)...
0
by: rn5a | last post by:
Suppose I have the following DataGrid: <asp:DataGrid ID="dgUsers" OnUpdateCommand="UpdateDG" runat="server"> <Columns> <TemplateColumn HeaderText="NAME"> <ItemTemplate> <asp:Label...
32
by: =?Utf-8?B?U2l2?= | last post by:
I have a form that I programmatically generate some check boxes and labels on. Later on when I want to draw the form with different data I want to clear the previously created items and then put...
9
by: dhtml | last post by:
I have written an article "Unsafe Names for HTML Form Controls". <URL: http://jibbering.com/faq/names/ > I would appreciate any reviews, technical or otherwise. Garrett --...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.