Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleDisplay FlexGrid data in an HTML table
KeywordsFlexGrid, sort, grid, HTML, Web
CategoriesControls, Utilities, Internet
 
Loop through the rows creating <TR> ... </TR> entries. For each row, loop through the columns creating <TD> ... </TD> entries.
 
Private Sub cmdShowHtml_Click()
Dim txt As String
Dim r As Integer
Dim c As Integer
Dim fname As String
Dim fnum As Integer

    ' Make an HTML string for the grid data.
    txt = "<TABLE BORDER=1 BGCOLOR=#00C0FF CELLPADDING=5>" _
        & vbCrLf

    ' Display the first row as a header.
    txt = txt & "<TR>" & vbCrLf
    For c = 0 To MSFlexGrid1.Cols - 1
        txt = txt & "  <TH>" & MSFlexGrid1.TextMatrix(0, c) _
            & "</TH>" & vbCrLf
    Next c
    txt = txt & "</TR>" & vbCrLf

    ' Display the rest of the rows.
    For r = 1 To MSFlexGrid1.Rows - 1
        txt = txt & "<TR>" & vbCrLf
        For c = 0 To MSFlexGrid1.Cols - 1
            txt = txt & "  <TD>" & _
                MSFlexGrid1.TextMatrix(r, c) & "</TD>" & _
                vbCrLf
        Next c
        txt = txt & "</TR>" & vbCrLf
    Next r

    txt = "<HTML><HEAD></HEAD><BODY>" & vbCrLf & _
        txt & "</BODY></HTML>"

    ' Save the text into a file.
    fname = App.Path
    If Right$(fname, 1) <> "\" Then fname = fname & "\"
    fname = fname & "temp.htm"

    fnum = FreeFile
    Open fname For Output As fnum
    Print #fnum, txt
    Close fnum

    ' Display the file.
    ShellExecute hwnd, "open", fname, vbNullString, _
        vbNullString, SW_SHOW
End Sub
 
This example also sorts the FlexGrid's columns.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated