简体   繁体   English

更改单元格/行颜色-在明确定义背景色后不更改

[英]Change cell/row colors - not changing after explicitly defining back color

I have some code written in VB.Net that, depending on certain situations, changes the cellstyle.backcolor of certain rows. 我有一些用VB.Net编写的代码,这些代码根据某些情况会更改某些行的cellstyle.backcolor。 The code works. 该代码有效。 Although, I encounter weird occurrences. 虽然,我遇到奇怪的事情。

If I change the color of an entire row to yellow, then change it back to white (specifically targeting one cell, so it sets the row color to white, and then targets a specific cell's defaultcellstyle.backcolor to white), then change the color of the entire row to gray, the one cell that was originally set to white will not change. 如果我将整行的颜色更改为黄色,则将其更改回白色(专门针对一个单元格,因此它将行颜色设置为白色,然后将特定单元格的defaultcellstyle.backcolor设置为白色),然后更改颜色整行显示为灰色,原来设置为白色的一个单元格将不会更改。

Why is this? 为什么是这样? Do the row colors not supersede the cell style colors? 行颜色不会取代单元格样式颜色吗? The cell that's explicitly targeted can be either white or gray, so this is why it has to be targeted, i have only tested it in the situations where it is explicitly stated as white, however. 明确指定为目标的单元格可以是白色或灰色,因此这就是为什么必须指定其为目标单元的原因,但是我仅在明确表示为白色的情况下对其进行了测试。

edit: The code is below (it's loaded on formload). 编辑:下面的代码(它加载在formload上)。 The first time it runs through this it's fine and works. 第一次运行就可以了。 Depending on if I trigger a click event within the contained datagridview, the second time it runs through it may not color the forecolor to tomato. 根据我是否在所包含的datagridview中触发click事件,第二次运行它可能不会使前景色变成番茄。 Everytime I step through the code, it always hits the cell formatting. 每当我单步执行代码时,它总是会命中单元格格式。 I'm unsure as to why after the datagridview click, the next iteration of filterrows() will hit the cell formatting, but will NOT be reflected in the datagridview. 我不确定为什么单击datagridview之后,filterrows()的下一次迭代将达到单元格格式,但不会反映在datagridview中。 After filterrows(), the form/DGV are displayed. 在filterrows()之后,将显示表单/ DGV。

        Public Sub filterrows()
    Dim intCount As Integer = 0

    'PROCESS THROUGH LCC_RETAINED FOR ACCOUNTING MESSAGES AND TEMP CARDS
    For Each row As chgltrDataSet.BCL_CC_Select_DataRow In frmFinBatchChrg.ChgltrDataSet.BCL_CC_Select_Data
        If row.Item("LCC_RETAINED").ToString = "X" Then
            gridccselector.Rows(intCount).Cells(0).Style.ForeColor = Color.Tomato
            row.Item("LCC_CARD_TYPE") = ""
            row.Item("LCC_CC_EXP") = ""
            row.Item("LCC_NAME_ON_CARD") = ""
        ElseIf row.Item("LCC_RETAINED").ToString = "0" Then
            gridccselector.Rows(intCount).Cells(0).Style.ForeColor = Color.Yellow
        End If
        intCount += 1
    Next
End Sub

Figured it out. 弄清楚了。 I added the following to wherever the form closes. 我将以下内容添加到窗体关闭的任何地方。 I had this in one instance where the form closed (upon cancel) but not the other. 在一个实例中,我关闭了表单(取消时),而在另一个实例中却没有。

    Me.dispose()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM