Solved

I am having trouble with data types

Posted on 2003-11-24
8
284 Views
Last Modified: 2010-04-17
I am coding the UpdateCommand of a DataGrid in a VB.NET Webform.
I am having trouble with data types.
Specifically, the following statement works fine except that I don't want to read Cells(5).

        Dim ModelIDText As TextBox = CType(e.Item.Cells(5).Controls(0), TextBox)

When I replace Cells(5) with Cells(1), I get the following error:
[InvalidCastException: Specified cast is not valid.]

Cells(5) in my datagrid is type string
Cells(1) in my datagrid is type integer

How do I get ModelID to have the integer value of Cells(1)?

Thanks
Michael
0
Comment
Question by:michael5865
  • 2
8 Comments
 
LVL 6

Accepted Solution

by:
bkthompson2112 earned 250 total points
ID: 9811983
When you change to Cells(1), you're trying to cast an integer as a textbox.  Can't do.

I'm not at a .NET installation, but this should work:

Try:
CType(CType(e.Item.Cells(1).Controls(0),String),TextBox)

The inner CType(,String) will cast the integer to a string.
The outer Ctype(,TextBox) will cast _that_ string as a TextBox

0
 
LVL 44

Assisted Solution

by:Arthur_Wood
Arthur_Wood earned 250 total points
ID: 9812094
what are you trying to accomplish?  do you want to have a Textbox, in Cell1, that holds the Value of the ModelID?

If so, then you need to use the .ToString Method of the Integer in Cell(1)

AW
0
 

Author Comment

by:michael5865
ID: 9817610
Thanks for the help. The update is now working correctly.
To get it to work correctly, I had to make "visible" two coloums that are used as identifiers.
I believe I can set these column widths to zero so that in practice they are not visible.
I tried to do this in the properties of the datagrid but it didn't seem to make them dissappear. Can you tell me how to make two colums of a datagrid (that are required for the code but not for the user) -  invisible?

Thanks,

Michael
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 10244979
Right Click on the Datagrid, select Property Builder (I think that is the option - do not have .NET on this PC), then select column Builder.

Click on the first two columns listed (one at a time), and UNCHECK the Visible checkbox.

Those tow columns will then NOT be Visible, but will be present, and you can then get the value, as I indicated, earlier.

AW
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 86
Microsoft C++ code failing in executable that worked 9 85
tvirtualstringtree freeze when load too manny images 10 52
index Out OF Range Exception error 4 54
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now