February 3rd, 2008, 01:34 AM
How to change a particular row color of datagrid based on some condition.
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?
February 3rd, 2008, 11:14 AM
You can use the datagridviews RowPostPaint event to determine what color the row should be and to make it readonly
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
Originally Posted by yasinirshad
February 3rd, 2008, 12:34 PM
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.
Originally Posted by blicci