Datagridview Change cell color of non empty cell

心已入冬 提交于 2020-01-03 20:34:25

问题


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

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.


回答1:


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



回答2:


   '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


来源:https://stackoverflow.com/questions/19193823/datagridview-change-cell-color-of-non-empty-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!