#1
  1. No Profile Picture
    Contributing User
    ASP Discoverer (100 - 499 posts)

    Join Date
    Jul 2007
    Posts
    166
    Rep Power
    0

    How to change a particular row color of datagrid based on some condition.


    Hi,

    I want to change a particular row color of datagrid based on some condition. (windows form datagrid - vb.net 2003).

    Here in datagrid, first column is bool column.

    If the value for this bool column is true in database, then on form_load this bool col in grid will be checked else it will be unchecked.

    Now when this value in db is true, i want to change the color of the row in grid , say gray color.

    So how to change the color in datagrid based on this condition from db?

    Secondly, once this bool col is true in db and color of this row is gray, then i want to make this whole row (including bool column) as read only. Even when user tries to click on bool col, nothing shd happen (if value is true in db).

    How can i do that?

    Thanks.
  2. #2
  3. Contributing User
    ASP Discoverer (100 - 499 posts)

    Join Date
    Apr 2004
    Location
    Philly
    Posts
    466
    Rep Power
    133
    You can use the datagridviews RowPostPaint event to determine what color the row should be and to make it readonly
    Code:
    Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint
            Dim gvr As DataGridViewRow = Me.DataGridView1.Rows(e.RowIndex)
            If gvr.Cells(0).Value = True Then
                gvr.DefaultCellStyle.BackColor = Color.Gray
                gvr.ReadOnly = True
            End If
    End Sub


    Originally Posted by yasinirshad
    Hi,

    I want to change a particular row color of datagrid based on some condition. (windows form datagrid - vb.net 2003).

    Here in datagrid, first column is bool column.

    If the value for this bool column is true in database, then on form_load this bool col in grid will be checked else it will be unchecked.

    Now when this value in db is true, i want to change the color of the row in grid , say gray color.

    So how to change the color in datagrid based on this condition from db?

    Secondly, once this bool col is true in db and color of this row is gray, then i want to make this whole row (including bool column) as read only. Even when user tries to click on bool col, nothing shd happen (if value is true in db).

    How can i do that?

    Thanks.
  4. #3
  5. No Profile Picture
    Contributing User
    ASP Discoverer (100 - 499 posts)

    Join Date
    Jul 2007
    Posts
    166
    Rep Power
    0

    re


    Hi blicci,
    Thanks for reply.. But am using windows form - vb.net 2003 ..so i cant use datagridview...i guess its for .net 2005.

    So can you tell me how to do this in .net 2003 / refer article for the same.
    Thanks again.

    Originally Posted by blicci
    You can use the datagridviews RowPostPaint event to determine what color the row should be and to make it readonly
    Code:
    Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint
            Dim gvr As DataGridViewRow = Me.DataGridView1.Rows(e.RowIndex)
            If gvr.Cells(0).Value = True Then
                gvr.DefaultCellStyle.BackColor = Color.Gray
                gvr.ReadOnly = True
            End If
    End Sub

Similar Threads

  1. Datagrid
    By vbn in forum ASP Development
    Replies: 1
    Last Post: August 22nd, 2006, 04:04 AM
  2. Change an entire SubForm within a Tab based on Combo
    By GUID in forum Microsoft Access Help
    Replies: 4
    Last Post: August 26th, 2004, 06:27 AM
  3. Replies: 1
    Last Post: March 16th, 2004, 05:04 PM
  4. Replies: 0
    Last Post: November 16th, 2003, 02:32 PM
  5. Datagrid control return wrong page number.
    By mex in forum .NET Development
    Replies: 0
    Last Post: February 26th, 2003, 11:48 AM

IMN logo majestic logo threadwatch logo seochat tools logo