CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2001
    Posts
    155

    Save Contents in MSFlexgrid

    What's the code for saving the contents of an MSFlexgrid control????


    --Ant
    --------------------------------------------------
    check out my newest freeware
    E-mail me at: [email protected]
    for the address

  2. #2
    Join Date
    Jun 2001
    Location
    Memphis, TN
    Posts
    146

    Re: Save Contents in MSFlexgrid

    If someone can come up with a more sensible solution than this, I'd really really love to read it...

    Best way I know of to save the data in a Flexgrid is just to send it all to a text file. Write a Sub in a standard module that will export the data and write one that can load the data.

    To save it all, it would probably be best to use a nested for..next loop.

    For X = 1 to Flexgrid.Rows
    For Y = 1 to Flexgrid.Cols
    Buffer = Buffer & Flexgrid.Textmatrix(X,Y) & vbTab
    Next Y

    Buffer = Buffer & vbCrLf

    Next X

    ...or something of that nature.


  3. #3
    Join Date
    May 2001
    Posts
    155

    Re: Save Contents in MSFlexgrid

    ok, i got the load and save subs, but where would i put the for loop?

    --Ant
    --------------------------------------------------
    check out my newest freeware
    E-mail me at: [email protected]
    for the address

  4. #4
    Join Date
    Jun 2001
    Location
    Memphis, TN
    Posts
    146

    Re: Save Contents in MSFlexgrid

    Inside your save sub, create a string (i called it Buffer in my example) and then use that loop structure to create a big huge string that has all the rows on separate lines (thanks to the "Buffer = Buffer & vbCrLf" line) and it will have all the columbs tabbed (vbTab).

    Then you'll need some code to put the buffer in a file; I would use the CommonDialog control and use the .ShowSave method to allow the user to choose where to save the file.

    CommonDialog1.ShowSave
    Open CommonDialog1.Filename for Output As #1
    Print #1, Buffer
    Close #1

    Does that help some?


  5. #5
    Join Date
    May 2001
    Posts
    155

    Re: Save Contents in MSFlexgrid

    it helped. now i gotta put it all together.............

    --Ant
    --------------------------------------------------
    check out my newest freeware
    E-mail me at: [email protected]
    for the address

  6. #6
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Save Contents in MSFlexgrid

    Why do you want to save MSFlexGrid?. If you want tosave the content on the disk in order to download it later, I think it is a good solution to create a recordset from the flexgrid and save it as xml file

    Rst1.Save "c:\Temp\Recordset.xml", adPersistXML

    Later you can download from the file to the recordset and restore the flexgrid.
    Another advantage of this method is that it will save not only data but also a structure. For example you can save a content of MSHFlexGrid and retrieve the structure later.

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

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

Featured