Link to home
Start Free TrialLog in
Avatar of VBRocks
VBRocksFlag for United States of America

asked on

How to add tables to a RichTextBox control in .NET 2.0 programmatically?

Does anyone know how to to add tables to a RichTextBox programmatically?

I have a DataTable that could have around 10,000 rows in it.  My goal is to print 6 rows (records) per
page in 6-Up fashion.  I am using the RichTextBox, because i have to perform conditional formatting
(making key words Bold).  I'm hoping to layout a Table that has 2 columns and 3 rows per page,
so it would look like this:

            '     Position 1     |     Position 2

            ' ---------------------------------------

            '     Position 3     |     Position 4

            ' ---------------------------------------

            '     Position 5     |     Position 6


Thanks for your help!
SOLUTION
Avatar of Sancler
Sancler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of VBRocks

ASKER

I think that may be it Sancler.  Looks like it's VB6, but I can convert it to .NET.

I think the user control approach could work, if I were only displaying it on a Form, but I'm actually
going to send it to a printer, so I need it all laid out and formatted in 1 document.

I'm heading home for the night, so I'll have to get back with you and let you know how it turns out.

Thanks for your help!



ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Public Class RtfTableCell

    Private m_contents As Object

    Public Property Contents() As Object
        Get
            Return m_contents
        End Get
        Set(ByVal Value As Object)
            m_contents = Value
        End Set
    End Property

End Class
Public Class RtfTableColumn

    Private m_width As Integer = 100

    Public Property Width() As Integer
        Get
            Return m_width
        End Get
        Set(ByVal Value As Integer)
            m_width = Value
        End Set
    End Property

End Class
Public Class RtfTableRow

    Private m_cells As New List(Of RtfTableCell)

    Public ReadOnly Property Cells() As List(Of RtfTableCell)
        Get
            Return m_cells
        End Get
    End Property

End Class

Bob
Avatar of VBRocks

ASKER

Sancler, thank you very much for you help.  You definitely contributed!  However, TheLearnedOne
completely went the extra mile with posting the code that helped, so thank you TheLearedOne.

I did not end up using the RtfTableColumn, RtfTableRow, or RtfTableCell classes, but I created a new
RtfTable class that had the InsertTable sub that took a DataTable as a parameter, which I used
to build the table.

One note, I added code that made the border White so it could not be seen, because it seemed to print
no matter what I did.  That code was the first line of code, and it was:

    "{\colortbl ;\red255\green255\blue255;}"

Thank you both again!