conditional change of a datagridviews cell background color and text

旧城冷巷雨未停 提交于 2019-12-01 04:16:47
jvcoach23

I got it working... in the RowPostPaint event.. If I put in

if (my criteria here)
    Me.dgTableInfo.Rows(e.RowIndex).Cells("ColumnName").Style.BackColor = Color.Red
end if

Don't forget to set the selectoinBackColor too... otherwise if your red row changes, but you have it highlighted, it will look just like all the rest anyway.

This works without creating or calling multiple subs or functions. Seems to work for every instance I need it to.

Do While myDataReader.Read()
    ItemID = Trim(myDataReader.Item("ITEM").ToString())
    PAR = myDataReader.Item("PAR").ToString()
    Returned = myDataReader.Item("RETURNED_AMOUNT")
    Taken = myDataReader.Item("TAKEN_AMOUNT")
    OnHand = ((PAR + Returned) - Taken)

    DataGridViewItemList.Rows.Add(ItemID, PAR, Returned, Taken, OnHand)

    RI = DataGridViewItemList.Rows.Count - 1
    If OnHand <= (PAR / 2) Then
        DataGridViewItemList.Rows(RI).DefaultCellStyle.BackColor = Color.DarkSalmon
    Else
        DataGridViewItemList.Rows(RI).DefaultCellStyle.BackColor = Nothing
    End If
Loop
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!