Invalid Typecast, Newbie

J

Jim Bayers

I'm having a bear of a time with this. The error is, 'invalid type cast'.
I'm trying to create a checkbox for a datagrid. The check box shows up and
is bound properly, but when I go to update, and read the value from the
checkbox, I get the error. Just what is the 'checked' property type
anyway? I've tried nearly every type.

Dim f1 As String = CType(E.Item.Cells(2).Controls(0), TextBox).Text
Dim f2 As String = CType(E.Item.Cells(3).Controls(0), TextBox).Text
Dim f3 As Boolean = CType(E.Item.Cells(4).Controls(0),
CheckBox).Checked
Dim f4 As String = CType(E.Item.Cells(5).Controls(0), TextBox).Text

Is there an easy way to tell the type of something?
 
H

Herfried K. Wagner [MVP]

* Jim Bayers said:
I'm having a bear of a time with this. The error is, 'invalid type cast'.
I'm trying to create a checkbox for a datagrid. The check box shows up and
is bound properly, but when I go to update, and read the value from the
checkbox, I get the error. Just what is the 'checked' property type
anyway? I've tried nearly every type.

Dim f1 As String = CType(E.Item.Cells(2).Controls(0), TextBox).Text
Dim f2 As String = CType(E.Item.Cells(3).Controls(0), TextBox).Text
Dim f3 As Boolean = CType(E.Item.Cells(4).Controls(0),
CheckBox).Checked
Dim f4 As String = CType(E.Item.Cells(5).Controls(0), TextBox).Text

Is there an easy way to tell the type of something?

\\\
If TypeOf f Is Foo Then
...
End If
///
 
N

Nick Wilton

Try the system.convert classes in the .dotnet fx to use on primitves if you
are looking for performance in your app. Otherwise stick with the previous
advice.
 

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

Top