Notices

Great community. Great ideas.

Welcome to ASP/Free, a community dedicated to helping beginners and professionals alike in improving their knowledge of Microsoft's development and administration technologies. Sign up today to gain access to the combined insight of tens of thousands of members.

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

Results 1 to 3 of 3
Share This Thread →
  1. #1
    yasinirshad is offline Contributing User
    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
    blicci's Avatar
    blicci is offline Contributing User
    Join Date
    Apr 2004
    Location
    Philly
    Posts
    466
    Rep Power
    132
    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


    Quote 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.

  3. #3
    yasinirshad is offline Contributing User
    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.

    Quote 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

Share This Thread →

Become Part of This Conversation

Join NowFor Free!

Similar Threads

  1. Datagrid
    By vbn in forum ASP Development
    Replies: 1
    Last Post: August 22nd, 2006, 03: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, 05:27 AM
  3. Replies: 1
    Last Post: March 16th, 2004, 04:04 PM
  4. Replies: 0
    Last Post: November 16th, 2003, 01:32 PM
  5. Datagrid control return wrong page number.
    By mex in forum .NET Development
    Replies: 0
    Last Post: February 26th, 2003, 10:48 AM

ASP Free Advertisers and Affiliates