[英]change color of cell of dynamicly created datagridview
我有一組動態的數據網格,顯示從數據庫填充的(生產項目狀態的)隊列
'The datagridviews have already been created at form load.
'get the Qs list - returns datatable with list of queuenames.
Qlist = dbconnect.dbCall("SELECT * FROM QueueList")
For iQlist = 0 To Qlist.Rows.Count - 1
'iterate the queue List and populate the datagridview for showing that queue with any items in that queue
listContents = dbconnect.dbCall("SELECT itemName,queueEntryTime FROM " & Qlist.Rows(iQlist).Item("Q_name"))
'get the dynamic name of the datagridview
Dim controlName = "dg_" & Qlist.Rows(iQlist).Item("Q_name")
'assign the datatable containing its items to that datagridview
Me.tabQsAndServiceBays.Controls.Item(controlName).dataSource = listContents
'want to colour items in each datagrid that are over certain age.
'i.e. the items is in production queue for too long, something has gone wrong.
For Each dr As DataGridViewRow In tabQsAndServiceBays.Controls.Item(controlName).rows
'condition for each row based on cell's contents, if > 20mins mark different color.
If tabQsAndServiceBays.Controls.Item(controlName).Cells("queueEntryTime").Value > Now - 20 Then
dr.DefaultCellStyle.BackColor = Color.LightGreen
End If
'next
Next
我Public member 'rows' on type 'DataGrid' not found
的Public member 'rows' on type 'DataGrid' not found
錯誤。
我怎么能引用datagrid視圖的.datasource
屬性而不是.rows
?
如果那是實際錯誤msg, 'DataGrid'
而不是'DataGridView'
,則NET似乎認為您使用的是不能與DGV互換的DataGrid。 這里:
' 'item' is not needed, removed to prevent scroll
For Each dr As DataGridViewRow In tabQsAndServiceBays.Controls(controlName).rows
這里有兩個可能的錯誤。 首先,DataGridViewRow只能與DGV一起使用,因此無論如何,如果使用的是DataGrid,都會失敗。 其次,DataGrid沒有公共的Rows屬性。 DataGrid控件用於向后兼容和IIRC,您基本上是通過基礎ADO數據集訪問行的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.