conditional change of a datagridviews cell background color and text

后端 未结 3 629
醉话见心
醉话见心 2021-01-12 12:15

This is for a winform vb.net 2008 app. I\'m bringing data back from a database and based on some static conditions... i want to change the color of the background and the t

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-12 12:38

    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
    

提交回复
热议问题