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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.