Click here to Skip to main content
15,894,720 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good day to you all, Please i need help with this:

I have a datagrid control on a form with a checkbox column included. Now i want to pass the checked state property of the checkbox from the datagrid to the checkbox control on the form. The error i keep getting is

"Conversion from string type "True" to integer is not valid."

Any help with this will be highly appreciated.

Thanks in anticipation.
Frank

What I have tried:

Here is the code i am using to do that:
chkTapeSealed.Checked = CBool(CType(LoadingGrid.Cells(13).Value.ToString, CheckState))


I have also tried the following Code but got the same error:
chkTapeSealed.CheckState = CType(LoadingGrid.Cells(13).Value.ToString, CheckState)
Posted
Updated 17-Apr-17 2:46am
v2
Comments
Ralf Meier 17-Apr-17 7:57am    
Which Event from the DGV you use ?
Don't you address a Row from the DGV ?
Frankie-10589807 17-Apr-17 8:15am    
I am using the "RowHeaderMouseClick" event handler.
Here is the complete Code for the event:


"Private Sub dgvLoading_RowHeaderMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles dgvLoading.RowHeaderMouseClick

Dim LoadingGrid As DataGridViewRow = dgvLoading.SelectedRows(0)
Try
txtLoadinId.Text = LoadingGrid.Cells(0).Value.ToString
txtVReadyDate.Text = CStr(Convert.ToDateTime(LoadingGrid.Cells(1).Value.ToString()))
dtpVReadyTime.Text = LoadingGrid.Cells(2).Value.ToString
cmbVehicleName.Text = LoadingGrid.Cells(3).Value.ToString
cmbDriver.Text = LoadingGrid.Cells(4).Value.ToString
cmbDeestinationBranch.Text = LoadingGrid.Cells(5).Value.ToString
txtStartLoadingDate.Text = CStr(Convert.ToDateTime(LoadingGrid.Cells(6).Value.ToString()))
dtpstartLoadingTime.Text = LoadingGrid.Cells(7).Value.ToString
txtLoadingCompleteDate.Text = CStr(Convert.ToDateTime(LoadingGrid.Cells(8).Value.ToString()))
dtpLoadingCompleteTime.Text = LoadingGrid.Cells(9).Value.ToString
chkAttachedTransferSheet.Checked = CBool(CType(LoadingGrid.Cells(10).Value.ToString, CheckState))
txtTransferSheetNo.Text = LoadingGrid.Cells(11).Value.ToString
chkDoorSecurelyLocked.Checked = CBool(CType(LoadingGrid.Cells(12).Value.ToString, CheckState))
chkTapeSealed.Checked = CBool(CType(LoadingGrid.Cells(13).Value.ToString, CheckState))
txtTapeSealNo.Text = LoadingGrid.Cells(14).Value.ToString
txtDepartureDate.Text = CStr(Convert.ToDateTime(LoadingGrid.Cells(15).Value.ToString()))
dtpDepartureTime.Text = LoadingGrid.Cells(16).Value.ToString

Catch ex As Exception
MymsgBox.lblMsgHeader.Text = "Error..."
MymsgBox.lblMessage.Text = "Error Passing record to the controls..." & vbCrLf & ex.Message
MymsgBox.ShowDialog()
End Try

End Sub
End Class"

1 solution

I tried it like this :
VB
Private Sub DataGridView2_CellEnter(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView2.CellEnter
    If DataGridView2.Rows.Count > 0 Then
        CheckBox1.Checked = CBool(DataGridView2.Rows(e.RowIndex).Cells(0).Value)
    End If
 End Sub


You should notice that the Value of the Cell is refreshed when you leave the cell ...
Perhaps it helps you to get your code working ...

Edited :
To get the actual Value of a Cell like this you should call it like this :
VB
chkTapeSealed.Checked = CBool(LoadingGrid.Cells(13).EditedFormattedValue)
 
Share this answer
 
v2
Comments
Frankie-10589807 17-Apr-17 11:10am    
Thank you so much Ralf. I may not be able to use the CellEnter event because that field is not the only field i am pulling out of the grid. The record has up to 16 field which i want to pull into the respective controls, hence the reason i am using the RowHeaderMouseClick, or the CellContentClick events. Though i am still trying to get a hold of the Code that will resolve the issue.

Thanks again Ralf.
Ralf Meier 17-Apr-17 11:52am    
OK ... I have another approach for you - try it like this :
chkTapeSealed.Checked = CBool(LoadingGrid.Cells(13).EditedFormattedValue)
Frankie-10589807 17-Apr-17 12:09pm    
UUUUUUUUPP Ralf! You are a Genius! That single line of Code has saved a life.
Thank you soooooooooooooooooooooooooooooooo Very Much.
Keep the great work on Ralf. I appreciate.
Frankie-10589807 17-Apr-17 12:11pm    
Up Ralf! You are a Genius! Thank you so very much Ralf. This single line of Code has just saved a life. Please keep the great work on.
Ralf Meier 17-Apr-17 14:29pm    
You are welcome Frankie ... ;)
So would you please accept my answer and rate it ...?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900