DevExpress Winforms使用技巧教程:如何突出显示WinForms网格控件行

原创|使用教程|编辑:龚雪|2020-08-06 10:19:32.633|阅读 24 次

概述:DevExpress Winforms Controls 内置140多个UI控件和库,完美构建流畅、美观且易于使用的应用程序。

# 正版采购狂欢节,企业采购正当时 #

相关链接:

下载DevExpress v20.1完整版    DevExpress v20.1汉化资源获取

DevExpress Winforms Controls 内置140多个UI控件和库,完美构建流畅、美观且易于使用的应用程序。想要体验?点击下载>>

遇到的问题

在VB Windows Form上工作,有一下VB代码,该代码应该为带有NextCalibrationDate <= to today's date的行提供红色背景(在此情况下只有两行),但是没有实现。当调试应用程序时,似乎代码正在运行,但两行的颜色未更改为红色。目前想知道是否是因为在这些单元格中设置了日期的方式。

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

仅供参考,这是用来设置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()

DevExpress Winforms使用技巧教程:如何突出显示WinForms网格控件行
DevExpress Winforms使用技巧教程:如何突出显示WinForms网格控件行
解决方案

为了确保满足您的条件,请在更改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.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技术交流群2:775869749      欢迎一起进群讨论

获取第一手DevExpress控件资讯,请上DevExpress中文网!

慧都高端UI界面开发


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,尊重他人劳动成果

文章转载自:慧都网

登录 慧都网发表评论


暂无评论...

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
title
相关厂商
相关产品
DevExpress Universal Subscription

行业领先的界面控件开发包,帮助企业构建卓越应用!

DevExpress WinForms Subscription

为Windows Forms平台创建具有影响力的业务解决方案,高性价比WinForms界面控件套包。

在线
客服
咨询
电话
400-700-1020
在线
QQ
购物车 反馈 返回
顶部
在线客服系统
live chat