vb.net Datagridview 更改非空单元格的单元格颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19193823/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Datagridview Change cell color of non empty cell
提问by cotz
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.
我正在创建一个日历约会应用程序,我想在加载/打开应用程序时更改非空单元格(具有值的单元格)的 datagridview 的颜色。我的应用程序已经处理如何加载数据。我可以更改非空单元格的颜色,但在关闭并再次打开后,颜色恢复为默认值。
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 感谢您的帮助。
回答by cotz
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
回答by BINU NARAYANAN NELLIYAMPATHI
'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