Posted 16 March 2022, 12:45 pm EST
Dear all,
I use both functions below and they are working fine. Unlikely one cellStyle is overriding the other cellStyle. Is it possible to combine them in one cellStyle function so that the color can be set and at the same time the text can wrapped.
here is the code:
Function WrapCell()
Try
Dim cellStyleWrapped As CellStyle = Me.DG.Styles.Add(“Wrapped”, Me.DG.Styles.Normal)
cellStyleWrapped.WordWrap = True
Dim rw As Integer = 0 For Each r As Row In DG.Rows If rw = 0 Then Else 'Me.DG(rw, 2) = "Long text which should wrap" Me.DG.SetCellStyle(rw, 2, cellStyleWrapped) Me.DG.AutoSizeRow(rw) End If rw += 1 Next Catch ex As Exception MsgBox("Error 'WrapCell' : " & vbCrLf & ex.ToString, MsgBoxStyle.Critical) Finally 'Cursor.Current = Cursors.Default End Try
End Function
Private Function AssignForeColour() As Color
Try
For eRow As Integer = 1 To DG.Rows.Count - 1
'ForeColor
Dim csBlue As CellStyle = DG.Styles.Add(“csBlue”)
csBlue.ForeColor = Color.Blue
DG.Rows(eRow).Style = DG.Styles(“csBlue”)
DG.SetCellStyle(eRow, 2, csBlue)
Next
Catch ex As Exception MsgBox("Error 'AssignForeColour' :" & vbCrLf & ex.ToString, MsgBoxStyle.Critical) End Try
End Function
Best regards
Said