Results 1 to 3 of 3

Thread: [RESOLVED] Save all files in a tabcontrol

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2012
    Posts
    43

    Resolved [RESOLVED] Save all files in a tabcontrol

    I have created a WinForms program with a DevExPress tabcontrol! What I cant figure out is when the user clicks the form close button or Exit and they have multiple files in multiple tabpages and havent save any of them yet how do I get the program to ask to save all of them? I have this so far but only saves one file!
    Code:
    Function SaveChanges() As Boolean
            Dim reply As MsgBoxResult
            reply = MsgBox("Have you saved your document(s)?", MsgBoxStyle.YesNo + vbQuestion)
            If reply = MsgBoxResult.Yes Then
                tc1.SelectedTabPage.Dispose()
                tc1.SelectedTabPageIndex = tc1.SelectedTabPageIndex - 1
            End If
            If reply = MsgBoxResult.No Then
                SaveToolStripMenuItem.PerformClick()
                tc1.SelectedTabPageIndex = tc1.SelectedTabPageIndex - 1
            End If
        End Function
    I may be new,but I've been that way for a long time!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Save all files in a tabcontrol

    It's only saving one because you're only telling it to save one, i.e. the selected one. If you want to save the contents of every page then you have to visit every page. How do you usually visit every item in a collection? With a loop. One of the ideas behind Visual Basic is that the code reads rather like an English sentence, so simply speaking the task you need to perform can often give you a big clue to how to implement it. In this case, you want to save the contents of each page. That's a good indication that you should use a For Each loop.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2012
    Posts
    43

    Re: Save all files in a tabcontrol

    Thanks for your reply and setting me straight as you have for everyone in many of your post! I got it to work by using this code :

    Code:
    Function SaveChanges() As Boolean
            Dim strTabText As String = tc1.SelectedTabPage.Text
            Dim reply As MsgBoxResult
            reply = MsgBox("Have you saved your document(s)?", MsgBoxStyle.YesNo + vbQuestion)
            If reply = MsgBoxResult.Yes Then
                tc1.SelectedTabPage.Dispose()
            Else
                For Each Page As DevExpress.XtraTab.XtraTabPage In tc1.TabPages
                    If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
                        CType(Page.Controls.Item(0), AxXtremeSyntaxEdit.AxSyntaxEdit).SaveFileAs(SaveFileDialog1.FileName)
                        lastSavePath = SaveFileDialog1.FileName
                    End If
                Next Page
            End If
        End Function
    I may be new,but I've been that way for a long time!

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