473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Vb windows form: null value in datagrid

I am creating working in VB 2005 express edition on a windows form application, I am very new to VB, but do have some experience with Access and Access VBA
I am having some trouble with this code


Expand|Select|Wrap|Line Numbers
  1. Private Sub VehDataGridView_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles VehDataGridView.CellValidating
  2.         Dim row As Int16 = 0
  3.         Dim numrows As Int16 = Me.VehDataGridView.Rows.Count
  4.         Dim angle As Int16
  5.  
  6.  
  7.         While row + 1 < numrows
  8.  
  9.             Dim rownum As Int16 = 1 + row
  10.             angle = Me.VehDataGridView.Item(2, row).Value
  11.             checkangle(angle, rownum, row)
  12.  
  13.  
  14.             row += 1
  15.         End While
  16.  
  17.     End Sub
  18.     Sub checkangle(ByVal angle As Int16, ByVal rownum As Int16, ByVal row As Int16)
  19.         If angle > 360 Or angle < 0 Then
  20.             Dim message As String = " Pleese enter a angle between 0 and 360 in row " & rownum
  21.             MessageBox.Show(message, "input error", MessageBoxButtons.OK)
  22.             Me.VehDataGridView.Item(2, row).Value = 0
  23.  
  24.         End If
  25.     End Sub


When a new row is created in the datagrid it returns an exception

System.InvalidCastException was unhandled
Message="Conversion from type 'DBNull' to type 'Short' is not valid."


On the line
“angle = Me.VehDataGridView.Item(2, row).Value”

I can’t figure out how to handel this excepton.
What I want is, if the value is null the sub checkangle not be called

So far I cant seem to be able determine when the value of Me.VehDataGridView.Item(2, row) is null.

My guess is the answer is obvious but I cant seem to figure it out.

Thank you for your help
Oct 14 '07 #1
0 1181

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: PAUL EDWARDS | last post by:
I have a windows form that is bound to a datatable. In VB6 I could just update the field contents and it would be updated in the database, however if I update the text property of the control from...
2
by: Paul Daly (MCP) | last post by:
How do you access the value of a cell in a Windows form datagrid? I know this is how you would do it using an ASP.NET datagrid: DataGrid1.Items.Cells.Text However, "Items" is not available in...
0
by: Tim Haughton | last post by:
I've just released an article on using Test Driven Development with C# and Windows Forms. GUI's are often difficult to test, so I thought it might be of interest. The article along with the...
5
by: Jean Carlo | last post by:
Hello guys I`m developing a windows form that contain one Datagrid. In this datagrid I insert a checkBox Column. I need to get all rows where checkbox is checked by user. How do I get this...
4
by: chandru | last post by:
Hi there, I need to get the checked box unchecked in the boolcolumn by default, when the datagrid is loaded. Is there anyway to do it? I have removed the dbnull state from boolcolumn by...
1
by: Dmitry V. Markin | last post by:
Good day! Here is my problem: I need to have a radiobutton column in my DataGrid for a representation of a bool column, where only row can be checked at one time(only one value in bool column...
4
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I...
4
by: Steve A. | last post by:
Here is the scenario: I have a project that uses two forms. Form1 uses a SQL Connection, several DataAdapters for various tables, DataSet, and a DataView that I filter by user-selected field...
0
by: juanchipms | last post by:
I have a mdi form and a child form. in the mdi form i have a toolbar with some buttons on it and i enable or disable depends on what i want to do with the diferents forms. my problem is that i have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.