Home All Groups Group Topic Archive Search About
Author
5 Jun 2009 9:05 AM
Allen
Hello.  I have a windows form which contains a RichTextBox control,
rtNotes. At runtime this is filled with some data from a datatable using
the following code:

Dim sFont As New Font(rtNotes.Font, FontStyle.Regular)
Dim bFont As New Font(rtNotes.Font, FontStyle.Bold)

For Each dr As DataRow In dt.Rows
            'this sets the first part to be bold
            rtNotes.SelectionFont = bFont
            rtNotes.Text = rtNotes.Text & dr("DateEvent").ToString & " " &
dr("AgendaCode").ToString & " " & dr("PartyName").ToString & vbCrLf
            'this sets it back to standard
            rtNotes.SelectionFont = sFont
            rtNotes.Text = rtNotes.Text & dr("TranText").ToString & vbCrLf
& dr("longnote").ToString & vbCrLf & vbCrLf
        Next

I am trying to get the first line of the text to be BOLD and the rest of
the note to be standard text. However, when I view the RichTextBox, all of
teh text is in standard font.  I have also tried changing the
..SelectionFont to just .Font with the same result.  How can I get teh first
line of each record to be bold?

TIA

--
ats@jbex

It's easy to lay down and hide
Where's the warrior without his pride?

Adam and The Ants - Dog Eat Dog

Author
5 Jun 2009 4:41 PM
Matti
Hi!

Try this:

For Each dr As DataRow In dt.Rows
            'this sets the first part to be bold

            rtNotes.Text = rtNotes.Text & dr("DateEvent").ToString & " " &
dr("AgendaCode").ToString & " " & dr("PartyName").ToString & vbCrLf
rtNotes.SelectAll()
rtNotes.SelectionFont = bFont
rtNotes.SelectionLength = 0 ' This removes the selected area.
            'this sets it back to standard
            rtNotes.SelectionFont = sFont
            rtNotes.Text = rtNotes.Text & dr("TranText").ToString & vbCrLf
& dr("longnote").ToString & vbCrLf & vbCrLf
        Next

Actual You are trying to effect on selected text and nothing is selected
You don't need this line: rtNotes.SelectionFont = sFont
As there is nothing selected.

Regards!
Matti

"Allen" <at***@ignore.hotmail.ignore.com> kirjoitti
viestissä:jcmyqsdq0pju$.sux1zfjl6wgk$.***@40tude.net...
Show quoteHide quote
> Hello.  I have a windows form which contains a RichTextBox control,
> rtNotes. At runtime this is filled with some data from a datatable using
> the following code:
>
> Dim sFont As New Font(rtNotes.Font, FontStyle.Regular)
> Dim bFont As New Font(rtNotes.Font, FontStyle.Bold)
>
> For Each dr As DataRow In dt.Rows
>            'this sets the first part to be bold
>            rtNotes.SelectionFont = bFont
>            rtNotes.Text = rtNotes.Text & dr("DateEvent").ToString & " " &
> dr("AgendaCode").ToString & " " & dr("PartyName").ToString & vbCrLf
>            'this sets it back to standard
>            rtNotes.SelectionFont = sFont
>            rtNotes.Text = rtNotes.Text & dr("TranText").ToString & vbCrLf
> & dr("longnote").ToString & vbCrLf & vbCrLf
>        Next
>
> I am trying to get the first line of the text to be BOLD and the rest of
> the note to be standard text. However, when I view the RichTextBox, all of
> teh text is in standard font.  I have also tried changing the
> .SelectionFont to just .Font with the same result.  How can I get teh
> first
> line of each record to be bold?
>
> TIA
>
> --
> ats@jbex
>
> It's easy to lay down and hide
> Where's the warrior without his pride?
>
> Adam and The Ants - Dog Eat Dog
Author
10 Jun 2009 6:55 AM
Allen
On Fri, 5 Jun 2009 19:41:42 +0300, Matti wrote:

Show quoteHide quote
> Hi!
>
> Try this:
>
> For Each dr As DataRow In dt.Rows
>             'this sets the first part to be bold
>
>             rtNotes.Text = rtNotes.Text & dr("DateEvent").ToString & " " &
> dr("AgendaCode").ToString & " " & dr("PartyName").ToString & vbCrLf
> rtNotes.SelectAll()
>  rtNotes.SelectionFont = bFont
> rtNotes.SelectionLength = 0 ' This removes the selected area.
>             'this sets it back to standard
>             rtNotes.SelectionFont = sFont
>             rtNotes.Text = rtNotes.Text & dr("TranText").ToString & vbCrLf
> & dr("longnote").ToString & vbCrLf & vbCrLf
>         Next
>
> Actual You are trying to effect on selected text and nothing is selected
> You don't need this line: rtNotes.SelectionFont = sFont
> As there is nothing selected.
>
> Regards!
> Matti
>
> "Allen" <at***@ignore.hotmail.ignore.com> kirjoitti
> viestissä:jcmyqsdq0pju$.sux1zfjl6wgk$.***@40tude.net...
>> Hello.  I have a windows form which contains a RichTextBox control,
>> rtNotes. At runtime this is filled with some data from a datatable using
>> the following code:
>>
>> Dim sFont As New Font(rtNotes.Font, FontStyle.Regular)
>> Dim bFont As New Font(rtNotes.Font, FontStyle.Bold)
>>
>> For Each dr As DataRow In dt.Rows
>>            'this sets the first part to be bold
>>            rtNotes.SelectionFont = bFont
>>            rtNotes.Text = rtNotes.Text & dr("DateEvent").ToString & " " &
>> dr("AgendaCode").ToString & " " & dr("PartyName").ToString & vbCrLf
>>            'this sets it back to standard
>>            rtNotes.SelectionFont = sFont
>>            rtNotes.Text = rtNotes.Text & dr("TranText").ToString & vbCrLf
>> & dr("longnote").ToString & vbCrLf & vbCrLf
>>        Next
>>
>> I am trying to get the first line of the text to be BOLD and the rest of
>> the note to be standard text. However, when I view the RichTextBox, all of
>> teh text is in standard font.  I have also tried changing the
>> .SelectionFont to just .Font with the same result.  How can I get teh
>> first
>> line of each record to be bold?
>>
>> TIA
>>
>> --
>> ats@jbex
>>
>> It's easy to lay down and hide
>> Where's the warrior without his pride?
>>
>> Adam and The Ants - Dog Eat Dog

Thanks for this. I will give it a go and see what happens.
--
ats@jbex

But I learned to burn that bridge and delete
Those who compete...at a level that's obsolete
Instead I warm my hands upon the flames of the flag
As I recall our downfall
And the business that burned us all
See through the news and the views that twist reality

Rage Against The Machine - Bombtrack
Author
10 Jun 2009 7:55 AM
Allen
On Wed, 10 Jun 2009 07:51:43 +0100, Allen wrote:

Show quoteHide quote
> On Fri, 5 Jun 2009 19:41:42 +0300, Matti wrote:
>
>> Hi!
>>
>> Try this:
>>
>> For Each dr As DataRow In dt.Rows
>>             'this sets the first part to be bold
>>
>>             rtNotes.Text = rtNotes.Text & dr("DateEvent").ToString & " " &
>> dr("AgendaCode").ToString & " " & dr("PartyName").ToString & vbCrLf
>> rtNotes.SelectAll()
>>  rtNotes.SelectionFont = bFont
>> rtNotes.SelectionLength = 0 ' This removes the selected area.
>>             'this sets it back to standard
>>             rtNotes.SelectionFont = sFont
>>             rtNotes.Text = rtNotes.Text & dr("TranText").ToString & vbCrLf
>> & dr("longnote").ToString & vbCrLf & vbCrLf
>>         Next
>>
>> Actual You are trying to effect on selected text and nothing is selected
>> You don't need this line: rtNotes.SelectionFont = sFont
>> As there is nothing selected.
>>
>> Regards!
>> Matti
>>
>> "Allen" <at***@ignore.hotmail.ignore.com> kirjoitti
>> viestissä:jcmyqsdq0pju$.sux1zfjl6wgk$.***@40tude.net...
>>> Hello.  I have a windows form which contains a RichTextBox control,
>>> rtNotes. At runtime this is filled with some data from a datatable using
>>> the following code:
>>>
>>> Dim sFont As New Font(rtNotes.Font, FontStyle.Regular)
>>> Dim bFont As New Font(rtNotes.Font, FontStyle.Bold)
>>>
>>> For Each dr As DataRow In dt.Rows
>>>            'this sets the first part to be bold
>>>            rtNotes.SelectionFont = bFont
>>>            rtNotes.Text = rtNotes.Text & dr("DateEvent").ToString & " " &
>>> dr("AgendaCode").ToString & " " & dr("PartyName").ToString & vbCrLf
>>>            'this sets it back to standard
>>>            rtNotes.SelectionFont = sFont
>>>            rtNotes.Text = rtNotes.Text & dr("TranText").ToString & vbCrLf
>>> & dr("longnote").ToString & vbCrLf & vbCrLf
>>>        Next
>>>
>>> I am trying to get the first line of the text to be BOLD and the rest of
>>> the note to be standard text. However, when I view the RichTextBox, all of
>>> teh text is in standard font.  I have also tried changing the
>>> .SelectionFont to just .Font with the same result.  How can I get teh
>>> first
>>> line of each record to be bold?
>>>
>>> TIA
>>>
>>> --
>>> ats@jbex
>>>
>>> It's easy to lay down and hide
>>> Where's the warrior without his pride?
>>>
>>> Adam and The Ants - Dog Eat Dog
>
> Thanks for this. I will give it a go and see what happens.

Almost does it but the SelectAll line puts all preceeding text to Bold and
the SelectionLength = 0 means that nothing ever gets set to regular.  I
will play around with it for a while though :-)
--
ats@jbex

The world is my expense
The cost of my desire
Jesus blessed me with its future
And I protect it with fire

Rage Against The Machine - Sleep Now In The Fire
Author
10 Jun 2009 8:40 AM
Allen
On Wed, 10 Jun 2009 08:54:08 +0100, Allen wrote:

Show quoteHide quote
> On Wed, 10 Jun 2009 07:51:43 +0100, Allen wrote:
>
>> On Fri, 5 Jun 2009 19:41:42 +0300, Matti wrote:
>>
>>> Hi!
>>>
>>> Try this:
>>>
>>> For Each dr As DataRow In dt.Rows
>>>             'this sets the first part to be bold
>>>
>>>             rtNotes.Text = rtNotes.Text & dr("DateEvent").ToString & " " &
>>> dr("AgendaCode").ToString & " " & dr("PartyName").ToString & vbCrLf
>>> rtNotes.SelectAll()
>>>  rtNotes.SelectionFont = bFont
>>> rtNotes.SelectionLength = 0 ' This removes the selected area.
>>>             'this sets it back to standard
>>>             rtNotes.SelectionFont = sFont
>>>             rtNotes.Text = rtNotes.Text & dr("TranText").ToString & vbCrLf
>>> & dr("longnote").ToString & vbCrLf & vbCrLf
>>>         Next
>>>
>>> Actual You are trying to effect on selected text and nothing is selected
>>> You don't need this line: rtNotes.SelectionFont = sFont
>>> As there is nothing selected.
>>>
>>> Regards!
>>> Matti
>>>
>>> "Allen" <at***@ignore.hotmail.ignore.com> kirjoitti
>>> viestissä:jcmyqsdq0pju$.sux1zfjl6wgk$.***@40tude.net...
>>>> Hello.  I have a windows form which contains a RichTextBox control,
>>>> rtNotes. At runtime this is filled with some data from a datatable using
>>>> the following code:
>>>>
>>>> Dim sFont As New Font(rtNotes.Font, FontStyle.Regular)
>>>> Dim bFont As New Font(rtNotes.Font, FontStyle.Bold)
>>>>
>>>> For Each dr As DataRow In dt.Rows
>>>>            'this sets the first part to be bold
>>>>            rtNotes.SelectionFont = bFont
>>>>            rtNotes.Text = rtNotes.Text & dr("DateEvent").ToString & " " &
>>>> dr("AgendaCode").ToString & " " & dr("PartyName").ToString & vbCrLf
>>>>            'this sets it back to standard
>>>>            rtNotes.SelectionFont = sFont
>>>>            rtNotes.Text = rtNotes.Text & dr("TranText").ToString & vbCrLf
>>>> & dr("longnote").ToString & vbCrLf & vbCrLf
>>>>        Next
>>>>
>>>> I am trying to get the first line of the text to be BOLD and the rest of
>>>> the note to be standard text. However, when I view the RichTextBox, all of
>>>> teh text is in standard font.  I have also tried changing the
>>>> .SelectionFont to just .Font with the same result.  How can I get teh
>>>> first
>>>> line of each record to be bold?
>>>>
>>>> TIA
>>>>
>>>> --
>>>> ats@jbex
>>>>
>>>> It's easy to lay down and hide
>>>> Where's the warrior without his pride?
>>>>
>>>> Adam and The Ants - Dog Eat Dog
>>
>> Thanks for this. I will give it a go and see what happens.
>
> Almost does it but the SelectAll line puts all preceeding text to Bold and
> the SelectionLength = 0 means that nothing ever gets set to regular.  I
> will play around with it for a while though :-)

Got it. It works if I use the following:

For Each dr As DataRow In dt.Rows

            rtNotes.Select(Position, 0)
            rtNotes.SelectionFont = bFont
            rtNotes.SelectedText = dr("DateEvent").ToString & " " &
dr("AgendaCode").ToString & " " & dr("PartyName").ToString & vbCrLf
            Position += (dr("DateEvent").ToString & " " &
dr("AgendaCode").ToString & " " & dr("PartyName").ToString & vbCrLf).Length

            rtNotes.Select(Position, 0)
            rtNotes.SelectionFont = sFont
            rtNotes.SelectedText = dr("TranText").ToString & vbCrLf &
dr("longnote").ToString & vbCrLf & vbCrLf
            Position += (dr("TranText").ToString & vbCrLf &
dr("longnote").ToString & vbCrLf & vbCrLf).Length

        Next

--
ats@jbex

Those who died are justified, for wearing the badge, they're the chosen
whites
You justify those that died by wearing the badge, they're the chosen whites

Rage Against The Machine - Killing In The Name