2013-10-05 69 views
2

在創建日曆約會應用程序時,Id想要在加載/打開應用程序時更改非空單元格的datagridview(具有值的那些單元格)的顏色。 我的應用程序已經處理如何加載數據。 我可以更改非空單元格的顏色,但在關閉並再次打開後,顏色恢復爲默認值。Datagridview更改非空單元格的單元格顏色

林不知道正確的語法,或者如果我需要通過所有的單元格,像爲整個表做一個循環,並更改單元格的背景顏色。

VB.net 2012

所以我的問題是喜歡或我想達到的迴路;

如果單元格不爲空,則更改cell.color 感謝您的任何幫助。

回答

9

我設法解決它:

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 
-1
'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