-
Jun 11th, 2021, 12:24 AM
#1
Thread Starter
Junior Member
Help! Vb2010 +sqlite3 datagridview The transformation of checkbox value
I am a beginner of vb2010 + SQLite3, now I have a problem, please ask some experts
I add a DataGridView control to the form, set a column as datagridviewcheckboxcolumn type, and a Boolean field in SQLite3 database, where 0 represents false and 1 represents true. At the same time, the data is called into the dataset, and the data source of the column is set to the field.
The value of the column in the DataGridView control
falseValue=0
Truevalue=1
indeterminatevalue=0
Threestate=false
When the program is debugged, the data can be displayed normally. When the data is 0, the check box is blank. When the data is 1, the check box is checked
You can change the value by clicking the check box of any line with the mouse. However, when you click the check box of other lines, an error occurs. The prompt is as follows:
Exception in DataGridView:
Sytem.FormatE xception:0 Is not a valid value for Boolean.
Sytem.formatexception: the string is not recognized as a valid Boolean value.
In system. Boolean. Parse (string value)
In system. Componentmodel. Boolean converter. Convertfrom (itype descriptorcontext context, cultureinfo, culture, object value)
---The end of the internal exception stack trace---
In system. Componentmodel. Boolean converter. Convertfrom (itype descriptorcontext context, cultureinfo, culture, object value)
In system. Windows. Forms. DataGridView. Datagridviewdataconnection. Pushvalue (int32 boundcolumnindex, int32 columnindex, int32 rowindex, object value)
To replace this default dialog box, handle the dataerror event.
I searched the Internet and said that the value was not converted (because SQLite3 database uses 0 and 1 to represent false and true), so there was an error. Ask a master, how to change? In which event is the transformation better (with specific code)? One is 0, one is true, and the other is false. It's dizzy for a beginner
-
Jun 11th, 2021, 04:05 AM
#2
Re: Help! Vb2010 +sqlite3 datagridview The transformation of checkbox value
If you need to convert True and False to 1 and 0, the following should work:
variable = Math.Abs(CInt(boolean))
And welcome to the forum!
-
Jun 11th, 2021, 05:40 AM
#3
Thread Starter
Junior Member
Re: Help! Vb2010 +sqlite3 datagridview The transformation of checkbox value
Originally Posted by Peter Swinkels
If you need to convert True and False to 1 and 0, the following should work:
variable = Math.Abs(CInt(boolean))
And welcome to the forum!
Thank you for your reply,
Can you tell me in what event the above code is written so that the data can be written to the table of dataset?
-
Jun 11th, 2021, 09:43 PM
#4
Thread Starter
Junior Member
Re: Help! Vb2010 +sqlite3 datagridview The transformation of checkbox value
Thank you again for Peter Swinkels
I have already solved the problem
code:
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
Dim cell As DataGridViewCheckBoxCell = DataGridView1.Rows(e.RowIndex).Cells("Column3")
Dim checked As Boolean = cell.EditingCellFormattedValue
If checked Then
cell.Value = System.Boolean.TryParse(1, Boolean.TrueString)
Else
cell.Value = System.Boolean.TryParse(0, Boolean.FalseString)
End If
DataGridView1.RefreshEdit() 'It is very important, otherwise will go wrong!
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|