Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I added a checkbox and a new column to the datagridview. The checkbox is being checked automatically when adding data to this column. If we delete this data thinking it is not necessary
The checkbox is still checked. I mean, once I give the data, the checkbox must be checked, but if I remove this data, how to unchecked the automatic checkbox
Goes.
I am making this effort on VB.net.
Thanks in advance to the experienced collaborators.


What I have tried:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim checkboxcolumn As New DataGridViewCheckBoxColumn()
checkboxcolumn.HeaderText = "*"
checkboxcolumn.Width = 20
checkboxcolumn.Name = "checkboxcolomn"
DataGridView1.Columns.Insert(0, checkboxcolumn)
End Sub

Sub display_data()
Dim cmd As New SqlCommand("select * from tbl_Pro", con)
Dim da As New SqlDataAdapter(cmd)
Dim dt As New DataTable
dt.Clear()
da.Fill(dt)
DataGridView1.DataSource = dt
dt.Columns.Add("Qty")
End Sub
Private Sub DataGridView1_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
Dim cell1 As DataGridViewCheckBoxCell = DataGridView1.Rows(e.RowIndex).Cells(0)
cell1.Value = True
End Sub
Posted
Updated 12-Oct-21 8:55am
Comments
[no name] 8-Oct-21 15:03pm    
If you remove a row ("we delete this data"), how can you have a "checkbox" to uncheck?

If you had one, it would be .IsChecked or .Checked = false;

1 solution

Try
datagridviewXY.rows(1..n).cells("WithCheckbox").value = false 

or
datagridviewXY.rows(1..n).cells("WithCheckbox").value = true

for a checked checkbox.
 
Share this answer
 

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