CType(e.Item.Cells(3).Controls(1), textbox) fails when key is set to READONLY

K

Keith-Earl

The code could not be simpler:
Dim txtProjectID As TextBox = CType(e.Item.Cells(1).Controls(0), TextBox)

Dim dblProjectID As Double = CDbl(txtProjectID.Text)


Run-time exception thrown : System.ArgumentOutOfRangeException - Specified
argument was out of the range of valid values.
Parameter name: index

e.Item.Cell(1) is valid. When I take away the READONLY attribute everything
works fine. What is really bizzare is that ALL Cells throw the same error
when I set the READONLY attribute to TRUE. When I remove it I can reference
all Cells in the Quickwatch window and in code. ProjectID is one of two
keys. The end-user should never change my keys in this app.

To make it even more interesting, I have another simple app (simple
code/description table) that does not exhibit this behavior.

What gives?

Keith
 
M

MA

Keith-Earl said:
The code could not be simpler:
Dim txtProjectID As TextBox = CType(e.Item.Cells(1).Controls(0), TextBox)

Dim dblProjectID As Double = CDbl(txtProjectID.Text)


Run-time exception thrown : System.ArgumentOutOfRangeException - Specified
argument was out of the range of valid values.
Parameter name: index

e.Item.Cell(1) is valid. When I take away the READONLY attribute everything
works fine. What is really bizzare is that ALL Cells throw the same error
when I set the READONLY attribute to TRUE. When I remove it I can reference
all Cells in the Quickwatch window and in code. ProjectID is one of two
keys. The end-user should never change my keys in this app.

To make it even more interesting, I have another simple app (simple
code/description table) that does not exhibit this behavior.

What gives?

Keith

When e.Item.Cells(1).Controls(0) is read only, there is no TextBox in it.
Get the value via a string instead. I don´t use VB usually, but it could
look like this in C# (without testing ;) :
string strProjectID = e.Item.Cells(1).Text;

/Marre
 
K

Keith-Earl

Will try that and report back.

Please explain why I have a SIMPLE code/description table where the PK is
READONLY and it works.
 
E

Eliyahu Goldin

It's just a guess. Could be that if you set ReadOnly, the control renders as
internal cell text and not as a control? Then Controls(0) would throw an
exception.

Eliyahu
 
M

MA

Keith-Earl said:
Will try that and report back.

Please explain why I have a SIMPLE code/description table where the PK is
READONLY and it works.

Sorry, but I don´t know if I understand what you mean.

/Marre
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top