Posted 10 September 2017, 3:37 am EST
Hello Nico,
After setting the NewStyle’s BackColor to Blue, you reassigned the Color Red as its BackColor, that is why both the cells appear Red in Color.
You need to create two different styles for both the cells as follows :
[vb]
With C1FlexGrid1
Dim NewStyle1 As C1.Win.C1FlexGrid.CellStyle
NewStyle1 = .Styles.Add("NewStyle1")
NewStyle1.BackColor = System.Drawing.Color.Blue
.SetCellStyle(0, 0, NewStyle1)
Dim NewStyle2 As C1.Win.C1FlexGrid.CellStyle
NewStyle2 = .Styles.Add("NewStyle2")
NewStyle2.BackColor = System.Drawing.Color.Red
.SetCellStyle(1, 0, NewStyle2)
End With
[/vb]
You can also achieve the same effect using the OwnerDrawCell event of the Grid.
Set the DrawMode property of the Grid to ‘OwnerDraw’.
[vb]
C1FlexGrid1.DrawMode = C1.Win.C1FlexGrid.DrawModeEnum.OwnerDraw
'Use the following code to assign different colors to the cells
Private Sub C1FlexGrid1_OwnerDrawCell(sender As System.Object, e As C1.Win.C1FlexGrid.OwnerDrawCellEventArgs) Handles C1FlexGrid1.OwnerDrawCell
C1FlexGrid1.Cols(e.Col).StyleNew.BackColor = Color.White
If e.Col = 0 And e.Row = 0 Then
C1FlexGrid1.Cols(e.Col).StyleNew.BackColor = Color.Blue
End If
If e.Col = 0 And e.Row = 1 Then
C1FlexGrid1.Cols(e.Col).StyleNew.BackColor = Color.Red
End If
End Sub
[/vb]
Refer to the attached sample implementing the above.
Hope it helps.
Regards,
Reema
2013/06/Sample_FlexBackCOlor.zip