Re: [2005] MenuItem Checked
This is a pretty silly line:
VB Code:
If mymenu.CheckState = CheckState.Checked = True Then
It will compare CheckState.Checked to True, which will return False, and then compare that to mymenu.CheckState, which will also return False. To do what you intended it would have to be:
VB Code:
If (mymenu.CheckState = CheckState.Checked) = True Then
but that's silly too. Change it to:
Re: [2005] MenuItem Checked
Quote:
Originally Posted by jmcilhinney
This is a pretty silly line:
VB Code:
If mymenu.CheckState = CheckState.Checked = True Then
It will compare CheckState.Checked to True, which will return False, and then compare that to mymenu.CheckState, which will also return False. To do what you intended it would have to be:
VB Code:
If (mymenu.CheckState = CheckState.Checked) = True Then
but that's silly too. Change it to:
Silly!?! I work in the department of redundancy department therefore it makes perfect sense. ;)
Thanks, I wondered why it appeared to be true and came back false. :(
I'll give this baby a whirl. Thank you. Of course you're brilliant!
Re: [2005] MenuItem Checked
How can I get the application to save the settings I made for the menu? It's not saving those settings.
:(
Re: [2005] MenuItem Checked
There's never a need to compare anything to True or False in an If statement because in order to be compared to True or False it must already be a Boolean value, so there's no point comparing one Boolean value to another to get a third Boolean value. If you just pass the original value it will have the same effect. The Checked property of a menu item is a Boolean value, so you can just pass that directly to an If statement. If you were using a ThreeState CheckBox and you really did have to test the CheckState then you'd just compare the CheckState property to a known value. That returns a Boolean so you just use that without comparing to another Boolean literal.
Now, as to your current issue, what exactly do you mean by that last statement? Are you saying that you've used an application setting to persist the Checked property? If so, have created the setting with User or Application scope? If it's User then the current value should be saved automatically when you shut down. If it's Application then it won't because settings with Application scope are ReadOnly. If you want the value to be persisted but you want one value for all users instead of a different value for each user then you'll have to edit the config file yourself using an XmlDocument object. Before you do that make sure that it is in fact more appropriate to use Application scope than User.
Re: [2005] MenuItem Checked
Hi,
Thank you for responding. As soon as I saw what you wrote, I saw what I was doing wrong. It was silly because it was so obvious. I realized that I had to take a break from what I was doing--after I repaired that.
To explain about the settings not saving: When I remove the checkmark from my menuitem, "play mission" in this case, I'd like to never see the mission again. When I close and repopen my ap, the mission plays and the checkmark is back.
Additionally, in my UI, I have several buttons that have to be saved individually. So, my application has "Save settings on exit" unchecked. I have a command button for "Save" and "Save All." Depending upon the situation, the user can save the state of one command button (enabled or disabled) or just save them all. I've set this up in code.
I wondered if I had to add these two menu items to the same code or if there is some other way of doing it. I see you mentioned the config file and the Xmldocument. So, as I send this I'll go to that and see what I can figure out.
For this application, all settings are user-scope.
I really appreciate your help. My project on this is close to being done and if it wasn't for your help (it won't let me rate you anymore) and this board, I doubt I'd be this far on it.
Re: [2005] MenuItem Checked
Oh, one more thing, I was thinking of just creating a registry setting. I would set the setting to 1 for play the mission. Then if the user unclicks the check box, the code writes a 0 over the 1. Everytime the ap ran it would read the registry and do the right thing depending if it's a 1 or a 0. I can do this, but if .Net offers a better way such as the config file, I'd rather do that.
Re: [2005] MenuItem Checked
You have to either save all your settings or none. If you have unchecked the autosave box then you need to save the settings yourself. You would normally do that by calling My.Settings.Save.
Here's what I would recommend for you. You should create application settings with User scope for all the values that you do or might want to persist. All the ones that you definitely want to persist you can bind to control properties. All those that you may or may not want to persist you should not bind. When you load the relevant form you can manually assign the setting value to the control property. When you're done you can assign the value of the control property back to the seeting or not, depending on whether you want to persist it or not. You can then recheck the autosave option because you know that only those settings that you want saved have been updated.
Re: [2005] MenuItem Checked
Quote:
Originally Posted by jmcilhinney
You have to either save all your settings or none. If you have unchecked the autosave box then you need to save the settings yourself. You would normally do that by calling My.Settings.Save.
Here's what I would recommend for you. You should create application settings with User scope for all the values that you do or might want to persist. All the ones that you definitely want to persist you can bind to control properties. All those that you may or may not want to persist you should not bind. When you load the relevant form you can manually assign the setting value to the control property. When you're done you can assign the value of the control property back to the seeting or not, depending on whether you want to persist it or not. You can then recheck the autosave option because you know that only those settings that you want saved have been updated.
Hi,
Yesterday you provided this advice to another VB.Net developer:
http://www.vbforums.com/showthread.php?t=407066
This is the problem I'm having also, while I'm using the 2.x, would this work for me?
I followed your advice and I've still not been able to persist the state of the checkmarks.
Re: [2005] MenuItem Checked
Quote:
Originally Posted by Christineeve
Hi,
Yesterday you provided this advice to another VB.Net developer:
http://www.vbforums.com/showthread.php?t=407066
This is the problem I'm having also, while I'm using the 2.x, would this work for me?
I followed your advice and I've still not been able to persist the state of the checkmarks.
Nevermind, it doesn't work. Who knew saving a checkmark on a menu had to be so difficult.
Re: [2005] MenuItem Checked
It isn't difficult. You just bind to a setting and it's done. You're making it difficult by the fact that you wnat to persist other values sometimes but not others, but that's not difficult either. I've explained how to do it in post #8.
Re: [2005] MenuItem Checked
Quote:
Originally Posted by jmcilhinney
It isn't difficult. You just bind to a setting and it's done. You're making it difficult by the fact that you wnat to persist other values sometimes but not others, but that's not difficult either. I've explained how to do it in post #8.
Hi,
You explained it well. I performed those steps, but it still doesn't work. I am overlooking some detail but I cannot figure out what. I set this up exactly how I set up the settings for the command buttons but it still doesn't properly function.
Edit: Specifically, I have my.settings.save created but it still doesn't save the setting although the code is created and available for it to be set. Again, just like I set up the command buttons. In this case, the default for the state is true, when I uncheck, save and close, the application reopens with the default set to true.
I appreciate your willingness to continue to help me when I'm struggling to get this right. :)
Re: [2005] MenuItem Checked
Hi,
If you would take one more look, maybe your expert eye can see what I might be overlooking. To me it looks exactly like what I want, but my.settings.save just isn't changing the state from true to false, or indeterminate to false/true.
Here is the code snippets.
Thank you for looking at this problem again.
VB Code:
Private Sub DisplayWarningToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DisplayWarningToolStripMenuItem.Click
'Sets the status of the Display Warning either on or off.
Dim mywarning As New ToolStripMenuItem
'Dim myform As New Form
'Dim myform As New frmDFDisplay
Try
'myform.Show()
If mywarning.Checked Then
MsgBox("You have turned ON the display advisory. This advisory will appear everytime you play DarkFaction.", MsgBoxStyle.Information, "Mission Briefing")
'displaystatus = 1
Else
MsgBox("You have turned OFF the display advisory, it will no longer appear.", MsgBoxStyle.Information, "Mission Briefing")
'displaystatus = 0
End If
My.Settings.Save()
Catch ex As Exception
If Err.Number <> 0 Then
errLogger(Err.Number, Err.Description, Err.Source)
End If
Exit Sub
Finally
End Try
End Sub
Userscopesettings:
VB Code:
<Global.System.Configuration.UserScopedSettingAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Configuration.DefaultSettingValueAttribute("True")> _
Public Property DisplayWarningToolStripMenuItem() As Boolean
Get
Return CType(Me("DisplayWarningToolStripMenuItem"),Boolean)
End Get
Set
Me("DisplayWarningToolStripMenuItem") = value
End Set
End Property
and this for the settings of the project:
VB Code:
<setting name="DisplayWarningToolStripMenuItem" serializeAs="String">
<value>True</value>
Re: [2005] MenuItem Checked
I really don't understand what you're trying to achieve with that code. You have a Click event handler for a menu item in which you create a completely new menu item and then test its Checked property, and then you save your settings. Have you set the CheckOnClick property of the menu item to True so that it actually changes its Checked property when you click it? Have you bound the Checked property to the application setting? Why are you creating a new menu item and texting its Checked property instead of testing the Checked property of the menu item that weas just clicked? Why do you need to save the settings when it will done automatically when you exit the application?
Finally, and less importantly, that is not a good name for the setting. It's a Boolean, not a ToolStripMenuItem, so naming it "DisplayWarningToolStripMenuItem" does not describe what it represents. It should be named either "DisplayWarning" or "DisplayWarningToolStripMenuItemChecked" because those are the two things that its value actually represents.
Re: [2005] MenuItem Checked
Hi,
Yes I have set up the controls, their states are set to true and they are bound to application settings. The problem is that their state is not automatically saving. That is exactly my question, "Why aren't their states being saved?"
I do not know why I set the new menu instance. It was something I tried to get this to work.
I have no clue why something that should automcally be saving won't save.
It's no problem. I will give up and move on.