Saving String to Settings File System.Collection.Specialized.StringCollection Not Working
Using VS2017. When I call a PrintDialog button, I want to save some data to the Users Settings file. But of course I do not want any repeat data in the file. The following works, but only when I close the App, I want it to run at DialogResult.Yes;
...
ElseIf result = DialogResult.Yes Then ' Save the entered data and continue the print
'MessageBox.Show("Yes pressed")
If Not String.IsNullOrEmpty(cbPayToo.Text) Or Me.cbPayToo.Text = "" Then
If Not cbPayToo.Items.Contains(cbPayToo.Text) Then 'make sure the item to save does not exist
Dim strings(cbPayToo.Items.Count - 1) As String
cbPayToo.Items.CopyTo(strings, 0)
My.Settings.cbPayToo.Insert(0, cbPayToo.Text)
End If
End If
If Not String.IsNullOrEmpty(cbCheckAmount.Text) Or Me.cbCheckAmount.Text = "" Then
If Not cbCheckAmount.Items.Contains(strCheckAmount) Then 'make sure the item to save does not exist
Dim strings(cbCheckAmount.Items.Count - 1) As String
cbCheckAmount.Items.CopyTo(strings, 0)
My.Settings.cbCheckAmount.Insert(0, strCheckAmount)
End If
End If
If Not String.IsNullOrEmpty(cbMemoBox.Text) Or Me.cbMemoBox.Text = "" Then
If Not cbMemoBox.Items.Contains(cbMemoBox.Text) Then 'make sure the item to save does not exist
Dim strings(cbMemoBox.Items.Count - 1) As String
cbMemoBox.Items.CopyTo(strings, 0)
My.Settings.cbMemoBox.Insert(0, cbMemoBox.Text)
End If
End If
....
End If
I run this when I close the installed App, and it will write to Settings properly;
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
My.Settings.DateBox = DateBox.Location
My.Settings.CheckToName = cbPayToo.Location
My.Settings.DollarAmount = cbCheckAmount.Location
My.Settings.pbSig = pbSig.ImageLocation
My.Settings.MemoBox = cbMemoBox.Location
End Sub
What is odd is that when I run FormClosing, the Settings file is updated with the cb data. Can I not update the Settings file during runtime?
vb.net
add a comment |
Using VS2017. When I call a PrintDialog button, I want to save some data to the Users Settings file. But of course I do not want any repeat data in the file. The following works, but only when I close the App, I want it to run at DialogResult.Yes;
...
ElseIf result = DialogResult.Yes Then ' Save the entered data and continue the print
'MessageBox.Show("Yes pressed")
If Not String.IsNullOrEmpty(cbPayToo.Text) Or Me.cbPayToo.Text = "" Then
If Not cbPayToo.Items.Contains(cbPayToo.Text) Then 'make sure the item to save does not exist
Dim strings(cbPayToo.Items.Count - 1) As String
cbPayToo.Items.CopyTo(strings, 0)
My.Settings.cbPayToo.Insert(0, cbPayToo.Text)
End If
End If
If Not String.IsNullOrEmpty(cbCheckAmount.Text) Or Me.cbCheckAmount.Text = "" Then
If Not cbCheckAmount.Items.Contains(strCheckAmount) Then 'make sure the item to save does not exist
Dim strings(cbCheckAmount.Items.Count - 1) As String
cbCheckAmount.Items.CopyTo(strings, 0)
My.Settings.cbCheckAmount.Insert(0, strCheckAmount)
End If
End If
If Not String.IsNullOrEmpty(cbMemoBox.Text) Or Me.cbMemoBox.Text = "" Then
If Not cbMemoBox.Items.Contains(cbMemoBox.Text) Then 'make sure the item to save does not exist
Dim strings(cbMemoBox.Items.Count - 1) As String
cbMemoBox.Items.CopyTo(strings, 0)
My.Settings.cbMemoBox.Insert(0, cbMemoBox.Text)
End If
End If
....
End If
I run this when I close the installed App, and it will write to Settings properly;
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
My.Settings.DateBox = DateBox.Location
My.Settings.CheckToName = cbPayToo.Location
My.Settings.DollarAmount = cbCheckAmount.Location
My.Settings.pbSig = pbSig.ImageLocation
My.Settings.MemoBox = cbMemoBox.Location
End Sub
What is odd is that when I run FormClosing, the Settings file is updated with the cb data. Can I not update the Settings file during runtime?
vb.net
1
MakeMy.Settings.Save()
the last line of your FormClosing method.
– LarsTech
Nov 25 '18 at 0:04
@LArsTech "The following works, but only when I close the App", he already saves it on close, all you would do with that is save twice on close, he wants to save also on other than closing.
– CruleD
Nov 25 '18 at 2:37
After all the bunch of if statements, useMy.Settings.Save()
– preciousbetine
Nov 25 '18 at 2:41
add a comment |
Using VS2017. When I call a PrintDialog button, I want to save some data to the Users Settings file. But of course I do not want any repeat data in the file. The following works, but only when I close the App, I want it to run at DialogResult.Yes;
...
ElseIf result = DialogResult.Yes Then ' Save the entered data and continue the print
'MessageBox.Show("Yes pressed")
If Not String.IsNullOrEmpty(cbPayToo.Text) Or Me.cbPayToo.Text = "" Then
If Not cbPayToo.Items.Contains(cbPayToo.Text) Then 'make sure the item to save does not exist
Dim strings(cbPayToo.Items.Count - 1) As String
cbPayToo.Items.CopyTo(strings, 0)
My.Settings.cbPayToo.Insert(0, cbPayToo.Text)
End If
End If
If Not String.IsNullOrEmpty(cbCheckAmount.Text) Or Me.cbCheckAmount.Text = "" Then
If Not cbCheckAmount.Items.Contains(strCheckAmount) Then 'make sure the item to save does not exist
Dim strings(cbCheckAmount.Items.Count - 1) As String
cbCheckAmount.Items.CopyTo(strings, 0)
My.Settings.cbCheckAmount.Insert(0, strCheckAmount)
End If
End If
If Not String.IsNullOrEmpty(cbMemoBox.Text) Or Me.cbMemoBox.Text = "" Then
If Not cbMemoBox.Items.Contains(cbMemoBox.Text) Then 'make sure the item to save does not exist
Dim strings(cbMemoBox.Items.Count - 1) As String
cbMemoBox.Items.CopyTo(strings, 0)
My.Settings.cbMemoBox.Insert(0, cbMemoBox.Text)
End If
End If
....
End If
I run this when I close the installed App, and it will write to Settings properly;
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
My.Settings.DateBox = DateBox.Location
My.Settings.CheckToName = cbPayToo.Location
My.Settings.DollarAmount = cbCheckAmount.Location
My.Settings.pbSig = pbSig.ImageLocation
My.Settings.MemoBox = cbMemoBox.Location
End Sub
What is odd is that when I run FormClosing, the Settings file is updated with the cb data. Can I not update the Settings file during runtime?
vb.net
Using VS2017. When I call a PrintDialog button, I want to save some data to the Users Settings file. But of course I do not want any repeat data in the file. The following works, but only when I close the App, I want it to run at DialogResult.Yes;
...
ElseIf result = DialogResult.Yes Then ' Save the entered data and continue the print
'MessageBox.Show("Yes pressed")
If Not String.IsNullOrEmpty(cbPayToo.Text) Or Me.cbPayToo.Text = "" Then
If Not cbPayToo.Items.Contains(cbPayToo.Text) Then 'make sure the item to save does not exist
Dim strings(cbPayToo.Items.Count - 1) As String
cbPayToo.Items.CopyTo(strings, 0)
My.Settings.cbPayToo.Insert(0, cbPayToo.Text)
End If
End If
If Not String.IsNullOrEmpty(cbCheckAmount.Text) Or Me.cbCheckAmount.Text = "" Then
If Not cbCheckAmount.Items.Contains(strCheckAmount) Then 'make sure the item to save does not exist
Dim strings(cbCheckAmount.Items.Count - 1) As String
cbCheckAmount.Items.CopyTo(strings, 0)
My.Settings.cbCheckAmount.Insert(0, strCheckAmount)
End If
End If
If Not String.IsNullOrEmpty(cbMemoBox.Text) Or Me.cbMemoBox.Text = "" Then
If Not cbMemoBox.Items.Contains(cbMemoBox.Text) Then 'make sure the item to save does not exist
Dim strings(cbMemoBox.Items.Count - 1) As String
cbMemoBox.Items.CopyTo(strings, 0)
My.Settings.cbMemoBox.Insert(0, cbMemoBox.Text)
End If
End If
....
End If
I run this when I close the installed App, and it will write to Settings properly;
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
My.Settings.DateBox = DateBox.Location
My.Settings.CheckToName = cbPayToo.Location
My.Settings.DollarAmount = cbCheckAmount.Location
My.Settings.pbSig = pbSig.ImageLocation
My.Settings.MemoBox = cbMemoBox.Location
End Sub
What is odd is that when I run FormClosing, the Settings file is updated with the cb data. Can I not update the Settings file during runtime?
vb.net
vb.net
edited Nov 24 '18 at 22:53
Mgfranz
asked Nov 24 '18 at 22:46
MgfranzMgfranz
227
227
1
MakeMy.Settings.Save()
the last line of your FormClosing method.
– LarsTech
Nov 25 '18 at 0:04
@LArsTech "The following works, but only when I close the App", he already saves it on close, all you would do with that is save twice on close, he wants to save also on other than closing.
– CruleD
Nov 25 '18 at 2:37
After all the bunch of if statements, useMy.Settings.Save()
– preciousbetine
Nov 25 '18 at 2:41
add a comment |
1
MakeMy.Settings.Save()
the last line of your FormClosing method.
– LarsTech
Nov 25 '18 at 0:04
@LArsTech "The following works, but only when I close the App", he already saves it on close, all you would do with that is save twice on close, he wants to save also on other than closing.
– CruleD
Nov 25 '18 at 2:37
After all the bunch of if statements, useMy.Settings.Save()
– preciousbetine
Nov 25 '18 at 2:41
1
1
Make
My.Settings.Save()
the last line of your FormClosing method.– LarsTech
Nov 25 '18 at 0:04
Make
My.Settings.Save()
the last line of your FormClosing method.– LarsTech
Nov 25 '18 at 0:04
@LArsTech "The following works, but only when I close the App", he already saves it on close, all you would do with that is save twice on close, he wants to save also on other than closing.
– CruleD
Nov 25 '18 at 2:37
@LArsTech "The following works, but only when I close the App", he already saves it on close, all you would do with that is save twice on close, he wants to save also on other than closing.
– CruleD
Nov 25 '18 at 2:37
After all the bunch of if statements, use
My.Settings.Save()
– preciousbetine
Nov 25 '18 at 2:41
After all the bunch of if statements, use
My.Settings.Save()
– preciousbetine
Nov 25 '18 at 2:41
add a comment |
2 Answers
2
active
oldest
votes
It is because in your project settings>application you have checked "save my.settings on shutdown".
Add this to save it manually.
My.Settings.Save()
add a comment |
After all the if statements, save the settings:
ElseIf result = DialogResult.Yes Then ' Save the entered data and continue the print
'MessageBox.Show("Yes pressed")
If Not String.IsNullOrEmpty(cbPayToo.Text) Or Me.cbPayToo.Text = "" Then
If Not cbPayToo.Items.Contains(cbPayToo.Text) Then 'make sure the item to save does not exist
Dim strings(cbPayToo.Items.Count - 1) As String
cbPayToo.Items.CopyTo(strings, 0)
My.Settings.cbPayToo.Insert(0, cbPayToo.Text)
End If
End If
If Not String.IsNullOrEmpty(cbCheckAmount.Text) Or Me.cbCheckAmount.Text = "" Then
If Not cbCheckAmount.Items.Contains(strCheckAmount) Then 'make sure the item to save does not exist
Dim strings(cbCheckAmount.Items.Count - 1) As String
cbCheckAmount.Items.CopyTo(strings, 0)
My.Settings.cbCheckAmount.Insert(0, strCheckAmount)
End If
End If
If Not String.IsNullOrEmpty(cbMemoBox.Text) Or Me.cbMemoBox.Text = "" Then
If Not cbMemoBox.Items.Contains(cbMemoBox.Text) Then 'make sure the item to save does not exist
Dim strings(cbMemoBox.Items.Count - 1) As String
cbMemoBox.Items.CopyTo(strings, 0)
My.Settings.cbMemoBox.Insert(0, cbMemoBox.Text)
End If
End If
'Add this line to save the settings Immediately
My.Settings.Save()
'To update the settings without saving them , you can use My.Settings.Update()
....
End If
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53463014%2fsaving-string-to-settings-file-system-collection-specialized-stringcollection-no%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
It is because in your project settings>application you have checked "save my.settings on shutdown".
Add this to save it manually.
My.Settings.Save()
add a comment |
It is because in your project settings>application you have checked "save my.settings on shutdown".
Add this to save it manually.
My.Settings.Save()
add a comment |
It is because in your project settings>application you have checked "save my.settings on shutdown".
Add this to save it manually.
My.Settings.Save()
It is because in your project settings>application you have checked "save my.settings on shutdown".
Add this to save it manually.
My.Settings.Save()
answered Nov 24 '18 at 23:14
CruleDCruleD
515138
515138
add a comment |
add a comment |
After all the if statements, save the settings:
ElseIf result = DialogResult.Yes Then ' Save the entered data and continue the print
'MessageBox.Show("Yes pressed")
If Not String.IsNullOrEmpty(cbPayToo.Text) Or Me.cbPayToo.Text = "" Then
If Not cbPayToo.Items.Contains(cbPayToo.Text) Then 'make sure the item to save does not exist
Dim strings(cbPayToo.Items.Count - 1) As String
cbPayToo.Items.CopyTo(strings, 0)
My.Settings.cbPayToo.Insert(0, cbPayToo.Text)
End If
End If
If Not String.IsNullOrEmpty(cbCheckAmount.Text) Or Me.cbCheckAmount.Text = "" Then
If Not cbCheckAmount.Items.Contains(strCheckAmount) Then 'make sure the item to save does not exist
Dim strings(cbCheckAmount.Items.Count - 1) As String
cbCheckAmount.Items.CopyTo(strings, 0)
My.Settings.cbCheckAmount.Insert(0, strCheckAmount)
End If
End If
If Not String.IsNullOrEmpty(cbMemoBox.Text) Or Me.cbMemoBox.Text = "" Then
If Not cbMemoBox.Items.Contains(cbMemoBox.Text) Then 'make sure the item to save does not exist
Dim strings(cbMemoBox.Items.Count - 1) As String
cbMemoBox.Items.CopyTo(strings, 0)
My.Settings.cbMemoBox.Insert(0, cbMemoBox.Text)
End If
End If
'Add this line to save the settings Immediately
My.Settings.Save()
'To update the settings without saving them , you can use My.Settings.Update()
....
End If
add a comment |
After all the if statements, save the settings:
ElseIf result = DialogResult.Yes Then ' Save the entered data and continue the print
'MessageBox.Show("Yes pressed")
If Not String.IsNullOrEmpty(cbPayToo.Text) Or Me.cbPayToo.Text = "" Then
If Not cbPayToo.Items.Contains(cbPayToo.Text) Then 'make sure the item to save does not exist
Dim strings(cbPayToo.Items.Count - 1) As String
cbPayToo.Items.CopyTo(strings, 0)
My.Settings.cbPayToo.Insert(0, cbPayToo.Text)
End If
End If
If Not String.IsNullOrEmpty(cbCheckAmount.Text) Or Me.cbCheckAmount.Text = "" Then
If Not cbCheckAmount.Items.Contains(strCheckAmount) Then 'make sure the item to save does not exist
Dim strings(cbCheckAmount.Items.Count - 1) As String
cbCheckAmount.Items.CopyTo(strings, 0)
My.Settings.cbCheckAmount.Insert(0, strCheckAmount)
End If
End If
If Not String.IsNullOrEmpty(cbMemoBox.Text) Or Me.cbMemoBox.Text = "" Then
If Not cbMemoBox.Items.Contains(cbMemoBox.Text) Then 'make sure the item to save does not exist
Dim strings(cbMemoBox.Items.Count - 1) As String
cbMemoBox.Items.CopyTo(strings, 0)
My.Settings.cbMemoBox.Insert(0, cbMemoBox.Text)
End If
End If
'Add this line to save the settings Immediately
My.Settings.Save()
'To update the settings without saving them , you can use My.Settings.Update()
....
End If
add a comment |
After all the if statements, save the settings:
ElseIf result = DialogResult.Yes Then ' Save the entered data and continue the print
'MessageBox.Show("Yes pressed")
If Not String.IsNullOrEmpty(cbPayToo.Text) Or Me.cbPayToo.Text = "" Then
If Not cbPayToo.Items.Contains(cbPayToo.Text) Then 'make sure the item to save does not exist
Dim strings(cbPayToo.Items.Count - 1) As String
cbPayToo.Items.CopyTo(strings, 0)
My.Settings.cbPayToo.Insert(0, cbPayToo.Text)
End If
End If
If Not String.IsNullOrEmpty(cbCheckAmount.Text) Or Me.cbCheckAmount.Text = "" Then
If Not cbCheckAmount.Items.Contains(strCheckAmount) Then 'make sure the item to save does not exist
Dim strings(cbCheckAmount.Items.Count - 1) As String
cbCheckAmount.Items.CopyTo(strings, 0)
My.Settings.cbCheckAmount.Insert(0, strCheckAmount)
End If
End If
If Not String.IsNullOrEmpty(cbMemoBox.Text) Or Me.cbMemoBox.Text = "" Then
If Not cbMemoBox.Items.Contains(cbMemoBox.Text) Then 'make sure the item to save does not exist
Dim strings(cbMemoBox.Items.Count - 1) As String
cbMemoBox.Items.CopyTo(strings, 0)
My.Settings.cbMemoBox.Insert(0, cbMemoBox.Text)
End If
End If
'Add this line to save the settings Immediately
My.Settings.Save()
'To update the settings without saving them , you can use My.Settings.Update()
....
End If
After all the if statements, save the settings:
ElseIf result = DialogResult.Yes Then ' Save the entered data and continue the print
'MessageBox.Show("Yes pressed")
If Not String.IsNullOrEmpty(cbPayToo.Text) Or Me.cbPayToo.Text = "" Then
If Not cbPayToo.Items.Contains(cbPayToo.Text) Then 'make sure the item to save does not exist
Dim strings(cbPayToo.Items.Count - 1) As String
cbPayToo.Items.CopyTo(strings, 0)
My.Settings.cbPayToo.Insert(0, cbPayToo.Text)
End If
End If
If Not String.IsNullOrEmpty(cbCheckAmount.Text) Or Me.cbCheckAmount.Text = "" Then
If Not cbCheckAmount.Items.Contains(strCheckAmount) Then 'make sure the item to save does not exist
Dim strings(cbCheckAmount.Items.Count - 1) As String
cbCheckAmount.Items.CopyTo(strings, 0)
My.Settings.cbCheckAmount.Insert(0, strCheckAmount)
End If
End If
If Not String.IsNullOrEmpty(cbMemoBox.Text) Or Me.cbMemoBox.Text = "" Then
If Not cbMemoBox.Items.Contains(cbMemoBox.Text) Then 'make sure the item to save does not exist
Dim strings(cbMemoBox.Items.Count - 1) As String
cbMemoBox.Items.CopyTo(strings, 0)
My.Settings.cbMemoBox.Insert(0, cbMemoBox.Text)
End If
End If
'Add this line to save the settings Immediately
My.Settings.Save()
'To update the settings without saving them , you can use My.Settings.Update()
....
End If
answered Nov 25 '18 at 0:00
preciousbetinepreciousbetine
1,5871418
1,5871418
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53463014%2fsaving-string-to-settings-file-system-collection-specialized-stringcollection-no%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Make
My.Settings.Save()
the last line of your FormClosing method.– LarsTech
Nov 25 '18 at 0:04
@LArsTech "The following works, but only when I close the App", he already saves it on close, all you would do with that is save twice on close, he wants to save also on other than closing.
– CruleD
Nov 25 '18 at 2:37
After all the bunch of if statements, use
My.Settings.Save()
– preciousbetine
Nov 25 '18 at 2:41