DevExpress Winforms Controls 内置140多个UI控件和库,完美构建流畅、美观且易于使用的应用程序。想要体验击下载>>
问题:
在VB Windows Form项目上工作时,有以下代码,该代码应该为带有NextCalibrationDate <= to today’s date(在这种情况下只有两行)的行提供红色背景色,但是此效果没有实现。当调试应用程序时,代码似乎可以正常工作,但是两行的颜色并未更改为红色,目前想知道是否是因为在单元格中设置日期方式的问题。
Private Sub GridView1_RowStyle(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs) Handles GridView1.RowStyleDim nextCalibDate As DateDim I As IntegerDim DataRowCount As Integer = GridView1.DataRowCountDim View As GridView = senderFor I = 0 To DataRowCount - 1If IsDBNull(GridView1.GetRowCellValue(e.RowHandle, colNextCalibrationDt)) Then'NothingElsenextCalibDate = GridView1.GetRowCellValue(e.RowHandle, colNextCalibrationDt)If nextCalibDate <= Today.Date ThenIf (e.RowHandle >= 0) Thene.Appearance.BackColor = Color.RedEnd IfEnd IfEnd IfNextEnd Sub
仅供参考,这是用来设置NextCalibrationDate的代码:
Dim DataRowCount As Integer = GridView1.DataRowCountDataRowCount -= 1Dim DateCalibrated As Date = GridView1.GetRowCellValue(DataRowCount, colDateCalibrated)Dim NextCalibrationDt As String'Set NextCalibrationDtSelect Case CalibIntervalCase "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 ElseNextCalibrationDt = "NULL"End SelectIf NextCalibrationDt <> "NULL" ThenNextCalibrationDt = "'" & NextCalibrationDt & "'"End IfDim 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()


解决办法:
为确保满足条件,请在更改e.Appearance.BackColor属性的行中插入一个断点。在特定情况下,RowStyle事件提供的外观设置的优先级低于其他外观设置。启用e.HighPriority选项确保外观设置的最高优先级。此外,由于每个可见行都会引发RowStyle事件,因此您无需循环执行代码。
在代码结尾处设置e.HighPriority = True也可以解决此问题,并且不依赖循环。
Private Sub GridView1_RowStyle(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs) Handles GridView1.RowStyleDim nextCalibDate As DateDim I As IntegerDim View As GridView = senderIf IsDBNull(GridView1.GetRowCellValue(e.RowHandle, colNextCalibrationDt)) Then'NothingElsenextCalibDate = GridView1.GetRowCellValue(e.RowHandle, colNextCalibrationDt)If nextCalibDate <= Today.Date ThenIf (e.RowHandle >= 0) Thene.Appearance.BackColor = Color.RedEnd Ife.HighPriority = True 'override any other formattingEnd IfEnd IfEnd Sub
DevExpress Dashboard控件实操公开课4月即将开启,
专家名师在线直播,免费听课名额先到先得~
DevExpress技术交流群:775869749 欢迎一起进群讨论
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!