Results 1 to 2 of 2

Thread: Can you save a datagrig to a .txt file?[RESOLVED]

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2002
    Posts
    54

    Can you save a datagrig to a .txt file?[RESOLVED]

    Is it possible to save the contents of a datagrid to a .txt file using code similar to this:

    Private Sub SaveAs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
    SaveFileDialog1.Filter = "Text files (*.txt)|*.txt"
    SaveFileDialog1.ShowDialog()
    If SaveFileDialog1.FileName <> "" Then
    FIleOpen(1, SaveFileDialog1.FileName, OpenMode.Output)
    PrintLine(1, DataGrid1.(What do I put Here?)
    FileClose(1)
    Endif
    Last edited by Nintendo_Wizard; Jan 16th, 2003 at 12:23 PM.

  2. #2
    Hyperactive Member stingrae's Avatar
    Join Date
    Apr 2002
    Location
    Sydney
    Posts
    401
    one way, and maybe not the best, is:

    Code:
        Public Sub WriteGrid()
            Dim myFile As IO.File
            Dim SW As IO.StreamWriter
            Dim r As Integer
            Dim c As Integer
            SW = myFile.AppendText("c:\file.txt")
            For r = 0 To NumberOfRows - 1
                For c = 0 To NumberOfColumns - 1
                    SW.Write(DataGrid.Item(r,c))
                Next c
                SW.WriteLine()
            Next r
            SW.Close()
        End Sub
    "The passion lives to keep your faith, though all are different, all are great" ... Michael Hutchence 1960-1997.

    Windows & Web Developer
    Specialising in Visual Basic .Net & Client Server Programming & Client/Customer Relations Databases
    Sutherland Shire, Sydney Australia
    www.stingrae.com.au
    Developer of Arnold - Gym & Martial Arts Database Management System
    www.gymdatabase.com.au

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width