title: vb.net datagridview image column (change image - conditional)
body: <p>I'm struggling with image column in my vb.net datagridview.
  All what i want to do is that to change the image depending on a conditional time span.</p>
  
  <p>Here is the full code :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>con.Open()
          da.SelectCommand = New OleDbCommand(Q, con)
          da.Fill(ds)
          da.Fill(dt)
          DataGridView1.DataSource = dt
          con.Close()
  
          Dim receivedfrom As Date = Convert.ToDateTime(DateTimePicker1.Value)
          Dim receivedto As Date = Convert.ToDateTime(DateTimePicker2.Value)
          Dim difference As TimeSpan
          Dim received As Date
          Dim today As Date = today
          Dim imgcol As New DataGridViewImageColumn()
          Dim inImg As Image = My.Resources.red
          imgcol.Image = inImg
          DataGridView1.Columns.Add(imgcol)
          imgcol.HeaderText = ""
          imgcol.Name = "img"
          imgcol.DataPropertyName = "img"
          With DataGridView1
              .Columns("img").DisplayIndex = 1
              .Columns("img").Width = 28
              .Columns("AC_RECEIVEDDT").DisplayIndex = 2
          End With
  
  
          For rowIndex = 0 To DataGridView1.RowCount - 1
              received = DataGridView1.Rows(rowIndex).Cells("AC_RECEIVEDDT").Value
              difference = today.Subtract(received)
  
              If difference.Days &lt; 2 Then
                  DataGridView1.Rows(rowIndex).Cells("img").Value = My.Resources.green
              ElseIf difference.Days = 2 Then
                  DataGridView1.Rows(rowIndex).Cells("img").Value = My.Resources.yellow
              Else
                  DataGridView1.Rows(rowIndex).Cells("img").Value = My.Resources.red
              End If
          Next</code></pre>
  </div>
  </div>
  </p>
  
  
  
  <p>Now, when i open the application, all the images are coming in RED color only.</p>
  
  <p>I have added the column name = "img", that's why i got the images already, but my problem is that all the images are not being changed based on the received date value, all the images are showing in red.</p>
  
  <p>My plan was to have the case with a time span less than 2 days to appear with green image as an acceptable processing period. Equal to 2 = yellow image. More than 2 days = red.</p>
  
  <p>I do have the red image now for all the rows, but its not getting changed based on the if statement, all rows have RED as i have assigned it in the image column.</p>
  
  <p>Goal:</p>
  
  <p><a href="https://i.stack.imgur.com/093bU.png" rel="nofollow noreferrer">This is a DGV list with conditional status, that's exactly what i want to do</a></p>
  
  <p><a href="https://i.stack.imgur.com/wLmzx.png" rel="nofollow noreferrer">That's what appears to me now</a></p>
  
  <p>Clearly, it is not applying the IF statement, is there anything wrong ? Am i missing something ?</p>
  
  <p>Hope the idea is clear enough.</p>
  
  <p>Any help would be appreciated.
  Thanks !</p>