|
-
Mar 22nd, 2015, 03:37 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Can't update row back color when boolean field is clicked
Hi, I have a datagrid which contains a boolean field. When I test the program and click a row's checkbox, it can't change back color of the row immediately, as my code has an event "CellEndEdit", I have to leave the cell to change the color. I tried some other events however couldn't make them work.
What I want is to change row back color when the checkbox of the datagrid is clicked.
-
Mar 23rd, 2015, 08:40 AM
#2
Re: Can't update row back color when boolean field is clicked
I don't know what code you have attempted, but does this work:
Code:
Private Sub myDataGrid_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles MyDataGrid.CellContentClick
If MyDataGrid.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString() = "True" Then
MyDataGrid.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.CornflowerBlue
End If
End Sub
-
Apr 1st, 2015, 02:17 AM
#3
Thread Starter
Addicted Member
Re: [RESOLVED] Can't update row back color when boolean field is clicked
I've found the answer in another site
Code:
Private Sub dgv_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles dgv.CellValueChanged
Dim con1 As OleDbConnection = con
con1.Open()
Dim dt As New DataTable
Dim _command As OleDbCommand = New OleDbCommand()
_command.Connection = con1
_command.CommandText = "SELECT * FROM table_name WHERE " & likeContent & ""
dt.Load(_command.ExecuteReader)
Me.dgv.DataSource = dt
con1.Close()
End Sub
Private Sub dgv_CurrentCellDirtyStateChanged(sender As Object, e As EventArgs) Handles dgv.CurrentCellDirtyStateChanged
If dgv.IsCurrentCellDirty Then
dgv.CommitEdit(DataGridViewDataErrorContexts.Commit)
End If
End Sub
Thanks after all.
Tags for this Thread
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
|