0

我的场景:

我有一个带有列和行标题的 C1FlexGrid。此外,C1FlexGrid 的第一行是一个布尔行(复选框)。根据这些复选框的状态,所需的效果是禁用该列的单元格。困难在于,由于第一行是不得禁用的布尔数据类型,因此不能使用 .Cols(index).AllowEditing 属性。我已经使用 BeforeEdit 事件处理程序成功地实现了一种解决方法,以禁止更改列中的单元格,以及在禁用时将单元格变灰的 CellStyle。

Private Sub C1FlexGrid1_BeforeEdit(ByVal sender As Object, ByVal e As C1.Win.C1FlexGrid.RowColEventArgs) Handles C1FlexGrid1.BeforeEdit
    If e.Row > 1 And Me.C1FlexGrid1.Item(1, e.Col) = False Then e.Cancel = True
End Sub

Private Sub C1FlexGrid1_AfterEdit(ByVal sender As Object, ByVal e As C1.Win.C1FlexGrid.RowColEventArgs) Handles C1FlexGrid1.AfterEdit
    If e.Row = 1 And Me.C1FlexGrid1.Item(1, e.Col) = False Then
        Call FormatColAsDisabled(e.Col)
    ElseIf e.Row = 1 And Me.C1FlexGrid1.Item(1, e.Col) = True Then
        Call FormatColAsEnabled(e.Col)
    End If
End Sub

Private Sub FormatColAsDisabled(ByVal col As Integer)
    Dim color As C1.Win.C1FlexGrid.CellStyle
    color = Me.C1FlexGrid1.Styles.Add("Gray")
    color.BackColor = Drawing.Color.Gray

    For row As Integer = 2 To Me.C1FlexGrid1.Rows.Count - 1
        Me.C1FlexGrid1.SetCellStyle(row, col, color)
    Next
End Sub

Private Sub FormatColAsEnabled(ByVal col As Integer)
    For row As Integer = 2 To Me.C1FlexGrid1.Rows.Count - 1
        Me.C1FlexGrid1.SetCellStyle(row, col, Me.C1FlexGrid1.Styles("Normal"))
    Next
End Sub

我的问题

有没有办法只修改这些单元格的“突出显示”行为,使得禁用的单元格根本不突出显示?

4

1 回答 1

0

为了避免突出显示禁用的单元格,您可以将 BeforeSelChange 事件的 Cancel EventArgs 设置为 true,以防新选定的单元格是禁用的单元格。

Private Sub C1FlexGrid1_BeforeSelChange(sender As Object, e As RangeEventArgs) Handles C1FlexGrid1.BeforeSelChange
    If e.NewRange.r1 > 1 And Me.C1FlexGrid1.GetCellCheck(1, e.NewRange.c1) = CheckEnum.Unchecked Then
        e.Cancel = True
    End If
End Sub
于 2015-09-11T06:26:08.173 回答