Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have 1 column named as date.

but some rows are blank and some rows are filled with date in datagridview

now i want to colour the blank rows of date as green and filled date rows as red.

how do i do that?

what is the condition that i will write?

please can anyone help me

thanks in advance.

i will be very obliged
Posted
Updated 15-Jul-13 22:42pm
v2

XML
Hi Sudeshna,
Here i am giving you the code for your problem.
So do as you have done adding the data to the datagrid view. Now add these code for evaluation of the rowdata and its values for coloring.

<code>Dim i As Integer
        For i = 0 To DataGridView1.Rows.Count - 1
            If IsNothing(DataGridView1.Rows(i).Cells(0).Value) Then
                DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.Green
            Else
                DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.Red
            End If
        Next</code>
here the cells(0) refers to the column where the date data is entered. I think it will solve your problem.
Thank you
 
Share this answer
 
Comments
sudeshna from bangkok 16-Jul-13 5:23am    
thanks but there is no function like isnothing. its not showing
SITU.PATI 16-Jul-13 5:25am    
WHICH VERSION OF VISUAL STUDIO YOU ARE USING?
sudeshna from bangkok 16-Jul-13 5:30am    
visual studio 2008 express edition
SITU.PATI 16-Jul-13 5:30am    
USE THIS ONE ALSO.
Microsoft.VisualBasic.Information.IsNothing(DataGridView1.Rows(i).Cells(0).Value)INSTEAD OF ISNOTHING
sudeshna from bangkok 16-Jul-13 5:31am    
visual studio 9.0
VB
For Each rw As GridViewRow In dgrd_WWWH.Rows
            If String.IsNullOrEmpty(rw.Cells("date").ToString()) Then
                rw.BackColor = Drawing.Color.Green
            Else
                rw.BackColor = Drawing.Color.Red
            End If
        Next

this code for asp.net vb code
 
Share this answer
 
Comments
sudeshna from bangkok 16-Jul-13 5:11am    
thanks but i want the same code in vb.net not in asp.net
[no name] 16-Jul-13 5:16am    
yes little bit gridviewrow changes as datagridviewrow
sudeshna from bangkok 18-Jul-13 6:16am    
can you give me the code in vb.net instead of asp.net?
[no name] 18-Jul-13 6:57am    
For Each rw As DataGridViewRow In DataGridView1.Rows
If String.IsNullOrEmpty(rw.Cells("slno").Value) Then
rw.DefaultCellStyle.BackColor = Color.Green
Else
rw.DefaultCellStyle.BackColor = Color.Red
End If
Next

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900