[RESOLVED] Datagridview checkbox problem
Hello. Please bear with me I'm new to vb.net.
I have this datagridview problem.
Scenario:
My Database columns.
Code:
-isCleared (boolean)
-DateCleared (DateTime)
My DGV Columns:
Code:
-isCleared Column (CheckBox)
-DateCleared Column (Readonly Textbox)
My DGV will only accept edits.
What I want to accomplish in a row level (logic). I can't find the right DGV event to execute this logic.
Code:
if dgv.CurrentRow.Cells("IsCleared").Value = True then
dgv.CurrentRow.Cells("DateCleared").Value = Date.Today
else
dgv.CurrentRow.Cells("DateCleared").Value = nothing or dbnull?
end if
I tried experimenting with the DGV events I can't seem to make it work. All I get is a delayed effect.
Re: Datagridview checkbox problem
Re: [RESOLVED] Datagridview checkbox problem
Hi,
Good to see that you have solved this for yourself but here is another option for you using the CellContentClick Event of the DataGridView:-
vb.net Code:
Private Sub DataGridView1_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
If e.ColumnIndex = 0 Then
If CBool(DataGridView1.CurrentCell.EditedFormattedValue) Then
DataGridView1.CurrentRow.Cells("DateCleared").Value = Today
Else
DataGridView1.CurrentRow.Cells("DateCleared").Value = DBNull.Value
End If
End If
End Sub
Cheers,
Ian
Re: [RESOLVED] Datagridview checkbox problem
Quote:
Originally Posted by
IanRyder
Hi,
Good to see that you have solved this for yourself but here is another option for you using the CellContentClick Event of the DataGridView:-
vb.net Code:
Private Sub DataGridView1_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
If e.ColumnIndex = 0 Then
If CBool(DataGridView1.CurrentCell.EditedFormattedValue) Then
DataGridView1.CurrentRow.Cells("DateCleared").Value = Today
Else
DataGridView1.CurrentRow.Cells("DateCleared").Value = DBNull.Value
End If
End If
End Sub
Cheers,
Ian
Thanks IanRyder. I like your solution. It's better.