SAMPLE:
Private Sub dgvData_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles dgvData.CellFormatting
If dgvData.DataSource IsNot Nothing Then
Dim drv As DataRowView
Dim dt As DataTable = CType(dgvData.DataSource, DataSet).Tables(0)
If e.RowIndex >= 0 Then
If e.RowIndex <= dt.Rows.Count - 1 Then
drv = dt.DefaultView.Item(e.RowIndex)
Dim dfm As Date
Dim dto As Date
dfm = drv.Item("Period From")
dto = drv.Item("Period Upto")
If Now.Date >= dfm And Now.Date <= dto Then
e.CellStyle.ForeColor = dgvData.DefaultCellStyle.ForeColor
Else
e.CellStyle.ForeColor = SystemColors.GrayText
End If
End If
End If
End If
End Sub
Private Sub dgvData_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles dgvData.CellFormatting
If dgvData.DataSource IsNot Nothing Then
Dim drv As DataRowView
Dim dt As DataTable = CType(dgvData.DataSource, DataSet).Tables(0)
If e.RowIndex >= 0 Then
If e.RowIndex <= dt.Rows.Count - 1 Then
drv = dt.DefaultView.Item(e.RowIndex)
Dim dfm As Date
Dim dto As Date
dfm = drv.Item("Period From")
dto = drv.Item("Period Upto")
If Now.Date >= dfm And Now.Date <= dto Then
e.CellStyle.ForeColor = dgvData.DefaultCellStyle.ForeColor
Else
e.CellStyle.ForeColor = SystemColors.GrayText
End If
End If
End If
End If
End Sub