在上述代码的基础上,先在里面判断是否选中
- Dim colindex, rowindex As Int16
- colindex = C1TrueDBGrid1.SelectedCols.IndexOf(e.Column.DataColumn)
- rowindex = C1TrueDBGrid1.SelectedRows.IndexOf(e.Row)
- If colindex > -1 And rowindex > -1 Then
- Return
- End If
复制代码
然后再执行后续逻辑即可,完整代码如下
- Private Sub C1TrueDBGrid1_FetchCellStyle1(ByVal sender As Object, ByVal e As C1.Win.C1TrueDBGrid.FetchCellStyleEventArgs) Handles C1TrueDBGrid1.FetchCellStyle
- Dim colindex, rowindex As Int16
- colindex = C1TrueDBGrid1.SelectedCols.IndexOf(e.Column.DataColumn)
- rowindex = C1TrueDBGrid1.SelectedRows.IndexOf(e.Row)
- If colindex > -1 And rowindex > -1 Then
- Return
- End If
- If e.Col.Equals(1) Then
- If (C1TrueDBGrid1.Columns("销售数量").CellValue(e.Row) < 2) Then
- Dim fntFont As New Font(e.CellStyle.Font.Name, e.CellStyle.Font.Size, FontStyle.Bold)
- e.CellStyle.Font = fntFont
- e.CellStyle.BackColor = System.Drawing.Color.Red
- Else
- e.CellStyle.BackColor = System.Drawing.Color.YellowGreen
- End If
- End If
- If e.Col.Equals(2) Then
- If (C1TrueDBGrid1.Columns("销售金额").CellValue(e.Row) < 100) Then
- Dim fntFont As New Font(e.CellStyle.Font.Name, e.CellStyle.Font.Size, FontStyle.Bold)
- e.CellStyle.Font = fntFont
- e.CellStyle.BackColor = System.Drawing.Color.Red
- Else
- e.CellStyle.BackColor = System.Drawing.Color.YellowGreen
- End If
- End If
- End Sub
复制代码 |