我在我的vb.net datagridview中苦苦寻找image列。 我想要做的就是根据条件时间跨度来改变图像。
以下是完整代码:
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 < 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
&#13;
现在,当我打开应用程序时,所有图像都只有红色。
我添加了列名=&#34; img&#34;,这就是为什么我已经获得了图片,但我的问题是所有图片都没有根据收到的日期值进行更改,所有图像都以红色显示。
我的计划是将时间跨度小于2天的情况显示为绿色图像作为可接受的处理周期。等于2 =黄色图像。超过2天=红色。
我现在对所有行都有红色图像,但它没有根据if语句进行更改,所有行都有RED,因为我在图像列中指定了它。
目标:
This is a DGV list with conditional status, that's exactly what i want to do
显然,它没有应用IF声明,有什么不对吗?我错过了什么吗?
希望这个想法足够清楚。
任何帮助将不胜感激。 谢谢!
答案 0 :(得分:0)
提供的快照不显示列-- Compiles
test1 :: (a -> b) -> HFree Monad f a -> HFree Monad f b
test1 = fmap
-- Compiles
test2 :: a -> HFree Monad f a
test2 = pure
-- Doesn't compile
test3 :: a -> HFree Functor f a
test3 = pure
的值。无论如何,假设它包含日期范围,并且您希望根据差异显示颜色。试试以下。使用ac_receiveddt
代替Days
。
TotalDays
我添加了DateTime转换检查
If difference.Days < 2 Then
DataGridView1.Rows(rowIndex).Cells("img").Value = My.Resources.Resource1.green
ElseIf difference.Days = 2 Then
DataGridView1.Rows(rowIndex).Cells("img").Value = My.Resources.Resource1.yellow
End If