Question Unable to cast object of type 'System.Windows.Forms.DataGridViewTextBoxCell' to type

okman

New member
Joined
Feb 19, 2010
Messages
1
Programming Experience
Beginner
i am getting this error

Unable to cast object of type 'System.Windows.Forms.DataGridViewTextBoxCell' to type 'System.Windows.Forms.DataGridViewCheckBoxCell'.

here is what i did , someone pls help me out , thanks

Private Sub DataGridViewLeave_CellContentClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridViewLeave.CellContentClick

Dim ci As Integer = e.ColumnIndex
Dim ri As Integer = e.RowIndex
Dim o As Object
Dim id As Integer
Dim target As DataGridViewCheckBoxCell
Dim chk As DataGridViewCheckBoxCell
Dim chk2 As DataGridViewCheckBoxCell

o = DataGridViewLeave.Rows(ri).Cells("wat's up")
chk = CType(o, DataGridViewCheckBoxCell)

o = DataGridViewLeave.Rows(ri).Cells("nothing much")
chk2 = CType(o, DataGridViewCheckBoxCell)

o = DataGridViewLeave.Rows(ri).Cells(ci)
target = CType(o, DataGridViewCheckBoxCell)


If (Not CType(chk.Value, Boolean)) AndAlso (Not CType(chk2.Value, Boolean)) Then
MsgBox("Leave time is not verified by User/Supervisor")
target.EditingCellFormattedValue = Not CType(target.EditingCellFormattedValue, Boolean)

Exit Sub
End If

o = DataGridViewLeave.Rows(ri).Cells("ColumnLeaveLeaveID")

If o IsNot Nothing Then
id = Integer.Parse(CType(CType(o, System.Windows.Forms.DataGridViewTextBoxCell).Value(), String))
 
Back
Top