|
-
Aug 20th, 2012, 08:04 AM
#1
Thread Starter
Member
[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! 
-
Aug 20th, 2012, 08:13 AM
#2
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.
-
Aug 20th, 2012, 12:54 PM
#3
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|