Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

I am having trouble with data types

Posted on 2003-11-24
8
Medium Priority
?
296 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
4 Comments
 
LVL 6

Accepted Solution

by:
bkthompson2112 earned 1000 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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this post we will learn different types of Android Layout and some basics of an Android App.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Starting up a Project

877 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