Datagridview更改非空单元格的单元格颜色 [英] Datagridview Change cell color of non empty cell

查看:251
本文介绍了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

这篇关于Datagridview更改非空单元格的单元格颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆