Change the datagridview colour based on date

前端 未结 2 1002
轮回少年
轮回少年 2021-01-26 10:09

i got a datagridview which displays data from database(MS Access)

the datagridview display the data correctly..

now i want to change the colour of the dgvRemind

2条回答
  •  隐瞒了意图╮
    2021-01-26 11:10

    I did this one and it works , I just checked if the record is expired or about to expire within ongoing month. you can just change the date interval as your need. I used DataBinding Complete event of Data GridView

    Private Sub grdMembersInfo_DataBindingComplete(sender As System.Object, e As System.Windows.Forms.DataGridViewBindingCompleteEventArgs) Handles grdMembersInfo.DataBindingComplete
        For i = 0 To grdMembersInfo.Rows.Count - 1
            Dim expDate As Date = grdMembersInfo.Rows(i).Cells("iCardExpiryDate").Value
            If DateDiff(DateInterval.Month, Date.Now, expDate) <= 0 Then
                grdMembersInfo.Rows(i).DefaultCellStyle.BackColor = Color.LightPink
            Else
                grdMembersInfo.Rows(i).DefaultCellStyle.BackColor = Color.LightGreen
            End If
        Next
    End Sub
    

提交回复
热议问题