简体   繁体   English

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

[英]Datagridview Change cell color of non empty cell

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. 我正在创建一个日历约会应用程序,Id喜欢在加载/打开应用程序时更改非空单元格(具有值的那些)的datagridview的颜色。 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 ; 所以我的问题就像或者我想要达到的循环是;

if the cell is not empty then change cell.color thanks for any help. 如果单元格不是空的,那么更改cell.color感谢任何帮助。

I manage to solve it: 我设法解决它:

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
   'try this.........
   For i As Integer = 0 To DtGrd.Rows.Count - 1
        For ColNo As Integer = 4 To 7
            If Not DtGrd.Rows(i).Cells(ColNo).Value Is DBNull.Value Then

                DtGrd.Rows(i).Cells(ColNo).Style.BackColor = Color.Red
            End If
        Next
    Next

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

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