VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



A routine to insert tables in Richtextbox

by Mario Villanueva (4 Submissions)
Category: Custom Controls/Forms/Menus
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

This is a routine that add a table to the current selection in a RichTextBox. I didn't find how can I do this on the web, so I made it by looking on the rtf Specification. I expect that this would be helpfull for those who are using RTB. If you find how to fix the problems i found please send me your work. (Sorry for my english ;) )

Rate A routine to insert tables in Richtextbox

Public Sub InsertTable(Rtb as RichTextBox, vRows as integer,vCols as integer)
Dim A As String, i As Integer, j As Integer
A = "{\rtf1\ansi\ansicpg1252\deff0" & _
"{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}}" & _
"\viewkind4\uc1\trowd\trqc\trgaph108\trleft-8" & _
"\trbrdrt\brdrs\brdrw10" & _
"\trbrdrl\brdrs\brdrw10" & _
"\trbrdrb\brdrs\brdrw10" & _
"\trbrdrr\brdrs\brdrw10"
For i = 1 To vCols
  A = A & "\clbrdrt\brdrw15\brdrs" & _
      "\clbrdrl\brdrw15\brdrs" & _
      "\clbrdrb\brdrw15\brdrs" & _
      "\clbrdrr\brdrw15\brdrs" & _
      "\cellx" & _
      CStr((ScaleX(Rtb.Width, Rtb.Parent.ScaleMode, vbTwips) \ vCols * 2) * i) & _
      "\clbrdrt"
Next
A = A & "\pard\intbl\lang3082\f0\fs24"
For i = 1 To vRows
  A = A & "\intbl\clmrg"
  For j = 1 To vCols
    A = A & "\cell"
  Next
  A = A & "\row"
Next
A = A & "}"
Rtb.SelText = A
End Sub

Download this snippet    Add to My Saved Code

A routine to insert tables in Richtextbox Comments

No comments have been posted about A routine to insert tables in Richtextbox. Why not be the first to post a comment about A routine to insert tables in Richtextbox.

Post your comment

Subject:
Message:
0/1000 characters