Results 1 to 3 of 3

Thread: [RESOLVED] Can't update row back color when boolean field is clicked

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2013
    Posts
    200

    Resolved [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.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,371

    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
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2013
    Posts
    200

    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
  •  



Click Here to Expand Forum to Full Width