none
How to change vb .net datagridview row color based on grid checkbox value

    Question

  • Hai

     

    How to change vb .net datagridview row color based on grid checkbox  value. Having  bound DataGridView. BindingSource as data source.  called DGV. I m using this code under cell_formatting event

     

     

     

     For Each row As DataGridViewRow In dgv.Rows

     

                If row.Cells("PAID").Value = 1 Then

                      e.CellStyle.BackColor = Color.LightGreen

     

                End If

            Next

     

     

    The problem is dgv background color changes completely. .

     

    Please suggest me how to change the color exclusively the ROW which has PAID value True. to Light Green.

     

    Thanking You advance


    Inaocha
    • Edited by inaocha Sunday, July 03, 2011 11:32 AM -
    Sunday, July 03, 2011 10:51 AM

Answers

  •            
    Try this
    After u bind the grid view, check whether the value is true or not
    For i = 0 To dgv_partdetails.Rows.Count - 1
                    If dgv_partdetails.Rows(i).Cells(10).Value = 1 Then
                        dgv_partdetails.Rows(i).DefaultCellStyle.BackColor = Color.LightSkyBlue
                    End If
     Next
    dgv_partdetails is my grid view
    • Marked as answer by inaocha Sunday, July 03, 2011 9:39 PM
    Sunday, July 03, 2011 11:56 AM

All replies

  • Find here a sample on our website for what you ask

    http://www.vb-tips.com/DGVRowColor.aspx

    It is of course not exact but I assume you are a programmer


    Success
    Cor
    Sunday, July 03, 2011 11:10 AM
  • soory

    I could not get proper help as i m using  binding source as data source. if have any suggestion based on said condition please help.

     

     


    Inaocha
    Sunday, July 03, 2011 11:34 AM
  •            
    Try this
    After u bind the grid view, check whether the value is true or not
    For i = 0 To dgv_partdetails.Rows.Count - 1
                    If dgv_partdetails.Rows(i).Cells(10).Value = 1 Then
                        dgv_partdetails.Rows(i).DefaultCellStyle.BackColor = Color.LightSkyBlue
                    End If
     Next
    dgv_partdetails is my grid view
    • Marked as answer by inaocha Sunday, July 03, 2011 9:39 PM
    Sunday, July 03, 2011 11:56 AM
  • TY Shifad

     


    Inaocha
    Sunday, July 03, 2011 9:40 PM
  • Thank's
    Saturday, November 09, 2013 5:31 PM