I want to step through the rows returned by my DataView, extract some values
from some of its columns and append them as separate lines to the text of
various rich textbox
controls while possibly changing the color of each new line.
It seems as though I should use the Lines property but can't find a good
example. Below is my attempt to do it with the .Text property (which doesn't
work because no colors are displayed). I have also tried this with
..ForeColor instead of SelectionColor.
What I am doing wrong here and/or what is the right way to do it with
..Lines?
Imports System.Drawing.Color
Private Sub LoadRTB(ByRef myRTB As RichTextBox, ByVal dtWhichDate As Date)
'set up DataView filter for the single specified date
dvEventDataByDate.RowFilter = "EventDate = #" & dtWhichDate & "#"
Dim myDRV As DataRowView 'a single row of the filetered DataView
With myRTB
For Each myDRV In dvEventDataByDate
.SelectionColor = FetchColor Left(myDRV("EventName"), 1))
.Text = .Text & myDRV("EventName") & Space(1) &
myDRV("PatientID") & vbCrLf
Next myDRV
End With
End Sub
Private Function FetchColor(ByVal EventType$) As System.Drawing.Color
Select Case EventType$
Case "B"
FetchColor = Cyan
Case "D"
FetchColor = Blue
Case "I"
FetchColor = Green
Case "K"
FetchColor = Yellow
Case "L"
FetchColor = Black
Case "N"
FetchColor = Magenta
Case "S"
FetchColor = Red
Case Else
FetchColor = Black
End Select
End Function