473,386 Members | 1,798 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,386 software developers and data experts.

When trying to capture value of checkbox I get a caste error

347 100+
I have a form that has a datatable on it with the following code:

Expand|Select|Wrap|Line Numbers
  1. Imports System.Data.SqlClient
  2. Imports System.Data
  3. Public Class AddHoliday
  4.     Private Sub AddHoliday_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  5.         'TODO: This line of code loads data into the 'MDRDataSet5.scratchpad2' table. You can move, or remove it, as needed.
  6.         Me.Scratchpad2TableAdapter.Fill(Me.MDRDataSet5.scratchpad2)
  7.     End Sub
  8.  
  9.     Private Sub DataGridView1_DataError(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles DataGridView1.DataError
  10.         Dim msg = String.Format("DataError occurred:\{0}\{1}\DataErrorContext: {2}", e.Exception.GetType().ToString(), e.Exception.Message, e.Context)
  11.         MessageBox.Show(msg)
  12.     End Sub
  13.     Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
  14.         Dim ch1 As New DataGridViewCheckBoxCell()
  15.         ch1 = DirectCast(DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(0), DataGridViewCheckBoxCell)
  16.  
  17.         If ch1.Value Is Nothing Then
  18.             ch1.Value = False
  19.         End If
  20.         Select Case ch1.Value.ToString()
  21.             Case "True"
  22.                 ch1.Value = False
  23.                 Exit Select
  24.             Case "False"
  25.                 ch1.Value = True
  26.                 Exit Select
  27.         End Select
  28.     End Sub
  29.  
and when I try to debug it I get the error "Unable to cast object of type 'System.Windows.Forms.DataGridViewTextBoxCell' to type 'System.Windows.Forms.DataGridViewCheckBoxCell'."

The line of code that's throwing this error is
Expand|Select|Wrap|Line Numbers
  1.  ch1 = DirectCast(DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(0), DataGridViewCheckBoxCell)
  2.  
can someone assist me with this error?

Thank you

Doug
Apr 11 '11 #1
1 2078
Hello, Doug,

From the message, it sounds like .Cells(0) is returning a value of type DataGridViewTextBoxCell. So try changing the declaration of ch1 to that type. That is:

Dim ch1 As New DataGridViewTextBoxCell()

Cheers,
Randy
Apr 12 '11 #2

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

Similar topics

8
by: Mathieu Blais | last post by:
Hi, I need to capture the Script timeout error if that is possible. I know I can increase the timeout value in the server settings or in the scripts itself but I really want to make sure that no...
1
by: Jeff Thur | last post by:
I am getting this error when trying to run a stored procedure: Microsoft.VisualBasic.CompilerServices.LateBinding.LateInd exGet(Object o, Object args, String paramnames) +1361...
3
by: KevLow | last post by:
Hi, Hope some kind soul can help me out here.. I'm trying to programmatically modify the column headings of a crosstab query such that it can be dynamic based on user specified period (Month...
7
by: Dica | last post by:
i've used the sample code from msdn to create an encyption/decryption assembly as found here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetHT10.asp i'm...
1
by: יוני גולדברג | last post by:
Hi, While trying to create new directory i recieve the following error message: "System.IO.DirectoryNotFoundException: Could not find a part of the path "\\premfs16\sites". The path exists, even...
5
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As...
5
by: eholz1 | last post by:
Hello Newsgroup, I have "installed" pdo using "pecl install pdo" (it intalled version 1.0.3), I have added the line "extension=pdo.so" to my php.ini file, but when I try to use the PDO db ...
0
by: cwho.work | last post by:
Hi! We are using apache ibatis with our MySQL 5.0 database (using innodb tables), in our web application running on Tomcat 5. Recently we started getting a number of errors relating to...
1
by: sureshreddy | last post by:
Hi friends, I am working on project in which i need a color change for the selected cell when i check the checkbox. when i uncheck it the color should also disappear. If you didn't understand...
3
by: compuv | last post by:
I'm obtaining a weird message when I try to add the capability to write to a csv file into the formmail script that I'm using. Everything is fine initially and the email comes through to me perfectly...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.