找回密码
 立即注册

QQ登录

只需一步,快速开始

cn2008liulin
初级会员   /  发表于:2020-6-3 11:19  /   查看:2775  /  回复:4
本帖最后由 cn2008liulin 于 2020-6-3 11:22 编辑

,c1truedbgrid在fetchcellstyle中无法显示选择的数据范围,无法显示背景颜色

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

4 个回复

倒序浏览
Richard.Ma讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2020-6-3 12:15:27
沙发
本帖最后由 Richard.Ma 于 2020-6-3 12:31 编辑

问题已经收到,这个原因是选中时,truedbgrid仍然会触发FetchCellStyle事件来渲染,造成样式还是这样,
可以判断这个单元格选中时不执行里面的样式设置代码,但是这样可能还会有其他的问题,我需要先验证一下然后给你回复
回复 使用道具 举报
Richard.Ma讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2020-6-3 14:59:21
板凳
在上述代码的基础上,先在里面判断是否选中
  1.         Dim colindex, rowindex As Int16
  2.         colindex = C1TrueDBGrid1.SelectedCols.IndexOf(e.Column.DataColumn)
  3.         rowindex = C1TrueDBGrid1.SelectedRows.IndexOf(e.Row)
  4.         If colindex > -1 And rowindex > -1 Then
  5.             Return

  6.         End If
复制代码


然后再执行后续逻辑即可,完整代码如下

  1.     Private Sub C1TrueDBGrid1_FetchCellStyle1(ByVal sender As Object, ByVal e As C1.Win.C1TrueDBGrid.FetchCellStyleEventArgs) Handles C1TrueDBGrid1.FetchCellStyle
  2.         Dim colindex, rowindex As Int16
  3.         colindex = C1TrueDBGrid1.SelectedCols.IndexOf(e.Column.DataColumn)
  4.         rowindex = C1TrueDBGrid1.SelectedRows.IndexOf(e.Row)
  5.         If colindex > -1 And rowindex > -1 Then
  6.             Return

  7.         End If
  8.         If e.Col.Equals(1) Then
  9.             If (C1TrueDBGrid1.Columns("销售数量").CellValue(e.Row) < 2) Then
  10.                 Dim fntFont As New Font(e.CellStyle.Font.Name, e.CellStyle.Font.Size, FontStyle.Bold)
  11.                 e.CellStyle.Font = fntFont
  12.                 e.CellStyle.BackColor = System.Drawing.Color.Red
  13.             Else
  14.                 e.CellStyle.BackColor = System.Drawing.Color.YellowGreen
  15.             End If
  16.         End If
  17.         If e.Col.Equals(2) Then
  18.             If (C1TrueDBGrid1.Columns("销售金额").CellValue(e.Row) < 100) Then
  19.                 Dim fntFont As New Font(e.CellStyle.Font.Name, e.CellStyle.Font.Size, FontStyle.Bold)
  20.                 e.CellStyle.Font = fntFont
  21.                 e.CellStyle.BackColor = System.Drawing.Color.Red
  22.             Else
  23.                 e.CellStyle.BackColor = System.Drawing.Color.YellowGreen
  24.             End If
  25.         End If

  26.     End Sub
复制代码

评分

参与人数 1满意度 +5 收起 理由
cn2008liulin + 5 老师厉害,非常好!

查看全部评分

回复 使用道具 举报
cn2008liulin
初级会员   /  发表于:2020-6-3 16:19:44
地板
非常好,点赞!
回复 使用道具 举报
Richard.Ma讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2020-6-3 16:42:32
5#
嗯, 不客气
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部