Datagridview更改非空单元格的单元格颜色

Datagridview更改非空单元格的单元格颜色

问题描述:

在创建日历约会应用程序时,Id用于在加载/打开应用程序时更改非空单元格(具有值的那些)的datagridview的颜色。
我的应用程序已经处理如何加载数据。
我可以更改非空单元格的颜色,但在关闭后再次打开颜色将恢复为默认颜色。

Im creating a calendar appointment application, Id like to change the color of the datagridview of the non empty cell (those with value) upon loading/opening the application. my application already handles how to load the data. i'm able to change the color of the non empty cell but after closing and opening again the color is back to default.

我不知道正确的语法,或者如果我需要遍历所有的单元格,像为整个表格做一个循环,并改变单元格的背景颜色。

Im not sure with the correct syntax , or if i need to go through all the cells like do a loop for the entire table and change the cell back color.

VB.net 2012

VB.net 2012

所以我的问题是或我想达到的循环是

so my questions is like or the loop i wanted to attain is ;

如果单元格不为空,

我设法解决它:

Dim dgv As DataGridView = Me.TblCalendarDataGridView

    For i As Integer = 0 To dgv.Rows.Count - 1
        For ColNo As Integer = 4 To 7
            If Not dgv.Rows(i).Cells(ColNo).Value Is DBNull.Value Then

                dgv.Rows(i).Cells(ColNo).Style.BackColor =  vbcolor.blue
            End If
        Next
    Next