原創(chuàng)|使用教程|編輯:龔雪|2020-04-27 09:26:21.330|閱讀 539 次
概述:DevExpress Winforms Controls 內(nèi)置140多個(gè)UI控件和庫,完美構(gòu)建流暢、美觀且易于使用的應(yīng)用程序。本文主要為大家介紹如何在使用DevExpress Winforms時(shí),如何更改GridControl行的顏色。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
下載DevExpress v19.2完整版 DevExpress v19.2漢化資源獲取
DevExpress Winforms Controls 內(nèi)置140多個(gè)UI控件和庫,完美構(gòu)建流暢、美觀且易于使用的應(yīng)用程序。想要體驗(yàn)?點(diǎn)擊下載>>
在VB Windows Form項(xiàng)目上工作時(shí),有以下代碼,該代碼應(yīng)該為帶有NextCalibrationDate <= to today's date(在這種情況下只有兩行)的行提供紅色背景色,但是此效果沒有實(shí)現(xiàn)。當(dāng)調(diào)試應(yīng)用程序時(shí),代碼似乎可以正常工作,但是兩行的顏色并未更改為紅色,目前想知道是否是因?yàn)樵趩卧裰性O(shè)置日期方式的問題。
Private Sub GridView1_RowStyle(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs) Handles GridView1.RowStyle Dim nextCalibDate As Date Dim I As Integer Dim DataRowCount As Integer = GridView1.DataRowCount Dim View As GridView = sender For I = 0 To DataRowCount - 1 If IsDBNull(GridView1.GetRowCellValue(e.RowHandle, colNextCalibrationDt)) Then 'Nothing Else nextCalibDate = GridView1.GetRowCellValue(e.RowHandle, colNextCalibrationDt) If nextCalibDate <= Today.Date Then If (e.RowHandle >= 0) Then e.Appearance.BackColor = Color.Red End If End If End If Next End Sub
僅供參考,這是用來設(shè)置NextCalibrationDate的代碼:
Dim DataRowCount As Integer = GridView1.DataRowCount DataRowCount -= 1 Dim DateCalibrated As Date = GridView1.GetRowCellValue(DataRowCount, colDateCalibrated) Dim NextCalibrationDt As String 'Set NextCalibrationDt Select Case CalibInterval Case "D" NextCalibrationDt = DateAdd(DateInterval.Day, 1, DateCalibrated) Case "W" NextCalibrationDt = DateAdd(DateInterval.Day, 7, DateCalibrated) Case "M" NextCalibrationDt = DateAdd(DateInterval.Month, 1, DateCalibrated) Case "6mos" NextCalibrationDt = DateAdd(DateInterval.Month, 6, DateCalibrated) Case "Y" NextCalibrationDt = DateAdd(DateInterval.Year, 1, DateCalibrated) Case "B" NextCalibrationDt = DateAdd(DateInterval.Year, 2, DateCalibrated) Case "36mos" NextCalibrationDt = DateAdd(DateInterval.Year, 3, DateCalibrated) Case "N" NextCalibrationDt = "NULL" Case "Calibration Not Required" NextCalibrationDt = "NULL" Case Else NextCalibrationDt = "NULL" End Select If NextCalibrationDt <> "NULL" Then NextCalibrationDt = "'" & NextCalibrationDt & "'" End If Dim sqlString As String = "UPDATE [ToolingCalibration].[dbo].[tblToolCalibration] SET LastCalibrationDt = '" & DateCalibrated & "', NextCalibrationDt = " & NextCalibrationDt & " where RecordID = '" & ToolIdToEdit & "'" Dim toolCmd As New SqlCommand(sqlString, connCalibrationRecord) toolCmd.Connection.Open() toolCmd.ExecuteNonQuery() toolCmd.Connection.Close()
為確保滿足條件,請?jiān)诟膃.Appearance.BackColor屬性的行中插入一個(gè)斷點(diǎn)。在特定情況下,RowStyle事件提供的外觀設(shè)置的優(yōu)先級低于其他外觀設(shè)置。啟用e.HighPriority選項(xiàng)確保外觀設(shè)置的最高優(yōu)先級。此外,由于每個(gè)可見行都會引發(fā)RowStyle事件,因此您無需循環(huán)執(zhí)行代碼。
在代碼結(jié)尾處設(shè)置e.HighPriority = True也可以解決此問題,并且不依賴循環(huán)。
Private Sub GridView1_RowStyle(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs) Handles GridView1.RowStyle Dim nextCalibDate As Date Dim I As Integer Dim View As GridView = sender If IsDBNull(GridView1.GetRowCellValue(e.RowHandle, colNextCalibrationDt)) Then 'Nothing Else nextCalibDate = GridView1.GetRowCellValue(e.RowHandle, colNextCalibrationDt) If nextCalibDate <= Today.Date Then If (e.RowHandle >= 0) Then e.Appearance.BackColor = Color.Red End If e.HighPriority = True 'override any other formatting End If End If End Sub
DevExpress Dashboard控件實(shí)操公開課4月即將開啟,
DevExpress技術(shù)交流群:775869749 歡迎一起進(jìn)群討論
掃描關(guān)注DevExpress中文網(wǎng)微信公眾號,及時(shí)獲取最新動態(tài)及最新資訊
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都網(wǎng)