创建一个确认,该确认如果用户取消
因此,我目前有一个我有4个团队的表格,每个团队都有4个队友。这不会改变。
最初在程序启动时,它会自动选择“当前值”广播按钮带有空白数据的标签,您可以选择“编辑值”,可以通过按“大绿色应用”按钮来保存。这将数据存储在名为stteamname的2D阵列下,每当您再次选择“当前值”时,标签引用。
有4个无线电按钮可让您在团队之间切换。
我的问题是,当我更改无线电按钮时,将删除尚未保存的文本标签中的任何数据将被删除。
我通过添加a
但是,我唯一的问题是,在取消此消息后,单个按钮停留在当前选择中,这无济于事。
我通过使用rbteamname1.checked = true
(rbteamname 1至4为名为1-4的无线电按钮)解决此问题,以切换回上一个状态。
当然,无论如何,这都只能返回到rbteamname1,因此我使用了1D数组并选择案例来帮助解决此问题。
“”“
Dim RadioCounter(1) As Integer
下面的代码仅在负载上给出默认的无线电按钮值。
Sub DeclareRadio(RadioButton)
RadioButton(1) = 1
'结束sub
“”“
每当成功选择一个无线电按钮时,RadioCounter(1)分别设置为数字1-4。每当选择一个新的广播按钮时,RadioCounter(1)的值就会移动到RadioCounter(0),并且当前的无线电按钮的值是RadioCounter(1)。
如果用户选择否,则引用RadioCounter(0)的值,并且选择案例选择“单选”按钮。
(请注意,radioteam()用作存储团队名称和队友名称字符串变量在2D数组中正确的计数器:stteamname。我很可能会在解决此问题后立即将其与RadioCounter合并,一旦解决了此
)
问题 sub rbteamname1_checkedChanged(作为对象的发送者作为evensArgs)处理rbteamname1.CheckedChanged
'note txtTeamName starts at 0, however RadioTeam starts at 1, RadioTeam = 0 has no team designated to it.
'this function is for swapping teams via radio button, each time, a confirmation is given to make sure the user saves the current team, or risk deletion of the inputted data.
RadioCounter(1) = RadioCounter(0)
stTeamname(0, RadioTeam) = txtTeamName.Text
stTeamname(1, RadioTeam) = txtMate1.Text
stTeamname(2, RadioTeam) = txtMate2.Text
stTeamname(3, RadioTeam) = txtMate3.Text
stTeamname(4, RadioTeam) = txtMate4.Text
Dim Dialog As DialogResult
Dialog = MessageBox.Show("Are you sure you want to change team? Any unsaved changes will be lost. If this box shows on starting the program, just press no", "Change team?", MessageBoxButtons.YesNo)
If Dialog = DialogResult.No Then
'need to run function to check previous result of radio button'
Select Case RadioCounter(0)
Case 1
rbTeamName1.Checked = True
Case 2
rbTeamName2.Checked = True
Case 3
rbTeamName3.Checked = True
Case 4
rbTeamName4.Checked = True
End Select
ElseIf Dialog = DialogResult.Yes Then
RadioCounter(1) = 1 'this equals the respective number for each radio button'
RadioTeam = 1
txtTeamName.Text = stTeamname(0, RadioTeam)
txtMate1.Text = stTeamname(1, RadioTeam)
txtMate2.Text = stTeamname(2, RadioTeam)
txtMate3.Text = stTeamname(3, RadioTeam)
txtMate4.Text = stTeamname(4, RadioTeam)
lblTeamName.Text = stTeamname(0, RadioTeam)
lblMate1.Text = stTeamname(1, RadioTeam)
lblMate2.Text = stTeamname(2, RadioTeam)
lblMate3.Text = stTeamname(3, RadioTeam)
lblMate4.Text = stTeamname(4, RadioTeam)
End If
End Sub
“”“
....或应该这样做。但这不是。我不确定为什么,但是当我强迫它来检查特定的广播按钮时,通过删除选定案例,并且仅运行rbteamname4.checked = true
它可以很好地工作根本不运行代码。
另外,尽管stteamname(0,radioteam)= txtteamname.text
等。仍然不会保存这些参数,我觉得这很奇怪。
理想的解决方案是什么?
要澄清:
如果用户写下团队名称和队友,并且不按“应用按钮”保存,然后选择另一个广播按钮来更改团队,则应出现一个文本框,询问他们是否要切换团队并丢失数据(是)或停留在上一个广播按钮上进行编辑并应用数据(否)。
按下NO后,该程序会自动将当前的单调按钮切换到上一个选择,使其似乎首先选择了无线电按钮。
我不确定我是否必须使它变得明显,但我对Stackoverflow和VB.NET的新手很新。先感谢您。
So I currently have a form where I have 4 teams, each with 4 teammates. This cannot change.
Initially when the program starts, it automatically selects the "current value" radio button which displays labels with blank data, you can then select "edit values" which can be saved by pressing the big green apply button. This stores the data under a 2d array named stTeamName, which the labels reference whenever you select "current value" again.
There are 4 radio buttons which allow you to switch between the teams.
My problem is, when I change the radio buttons, any data put into the text labels that has not been saved will be deleted.
I solved this problem by adding a message box which will stop the data in the labels from changing unless the user gives confirmation to do so.
However, my only problem is that after I cancel this, the radio button stays at the current selection which does not help.
I solved this issue by using rbTeamName1.Checked = True
(rbTeamname 1 to 4 being the radio buttons named team 1-4) to switch back to the previous state.
This of course only goes back to rbTeamname1 no matter what, so I employed an 1d array and select case to help solve this issue.
"""
Dim RadioCounter(1) As Integer
the code below simply gives the default Radio button value on load.`
Sub DeclareRadio(RadioButton)
RadioButton(1) = 1
End Sub
"""
Whenever a radio button is successfully selected, RadioCounter(1) is set to the number 1-4 respectively. Whenever a new radio button is selected, the value of RadioCounter(1) is moved to RadioCounter(0) and the current radio button's value is to RadioCounter(1).
If the user selects no, RadioCounter(0)'s value is referenced and a select case selects the radio button.
(Please note, RadioTeam() is used as a counter to store Team name and Teammate name string variables correctly within the 2d array: stTeamName. I will most likely merge this with RadioCounter as soon as I get this problem fixed)
"""
Private Sub rbTeamName1_CheckedChanged(sender As Object, e As EventArgs) Handles rbTeamName1.CheckedChanged
'note txtTeamName starts at 0, however RadioTeam starts at 1, RadioTeam = 0 has no team designated to it.
'this function is for swapping teams via radio button, each time, a confirmation is given to make sure the user saves the current team, or risk deletion of the inputted data.
RadioCounter(1) = RadioCounter(0)
stTeamname(0, RadioTeam) = txtTeamName.Text
stTeamname(1, RadioTeam) = txtMate1.Text
stTeamname(2, RadioTeam) = txtMate2.Text
stTeamname(3, RadioTeam) = txtMate3.Text
stTeamname(4, RadioTeam) = txtMate4.Text
Dim Dialog As DialogResult
Dialog = MessageBox.Show("Are you sure you want to change team? Any unsaved changes will be lost. If this box shows on starting the program, just press no", "Change team?", MessageBoxButtons.YesNo)
If Dialog = DialogResult.No Then
'need to run function to check previous result of radio button'
Select Case RadioCounter(0)
Case 1
rbTeamName1.Checked = True
Case 2
rbTeamName2.Checked = True
Case 3
rbTeamName3.Checked = True
Case 4
rbTeamName4.Checked = True
End Select
ElseIf Dialog = DialogResult.Yes Then
RadioCounter(1) = 1 'this equals the respective number for each radio button'
RadioTeam = 1
txtTeamName.Text = stTeamname(0, RadioTeam)
txtMate1.Text = stTeamname(1, RadioTeam)
txtMate2.Text = stTeamname(2, RadioTeam)
txtMate3.Text = stTeamname(3, RadioTeam)
txtMate4.Text = stTeamname(4, RadioTeam)
lblTeamName.Text = stTeamname(0, RadioTeam)
lblMate1.Text = stTeamname(1, RadioTeam)
lblMate2.Text = stTeamname(2, RadioTeam)
lblMate3.Text = stTeamname(3, RadioTeam)
lblMate4.Text = stTeamname(4, RadioTeam)
End If
End Sub
"""
....Or it should do that. But it doesnt. Im not sure why, but when I force it to check a specific radio button, by removing the select case and only running rbTeamName4.Checked = True
it will work perfectly fine, theres something about the select case that simply doesnt run the code.
Also, despite stTeamname(0, RadioTeam) = txtTeamName.Text
etc. being given before the messagebox shows, if I do not press the apply button to save, press another team button, then press no, it will still not save those parameters, which I find extremely weird.
What is the ideal solution to this?
To clarify:
If a user writes team names and teammates and does not press the apply button to save and then changes team by selecting another radio button, a text box should appear asking whether they want to switch team and lose the data (Yes) or stay on the previous radio button to edit and apply the data (No).
Upon pressing no, the program automatically switches the current radio button to the previous selection to make it seem as if no radio button was selected in the first place.
And im not sure if I have to make it obvious but im new to both stackoverflow and VB.net in general. Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
本质上,您要的是肮脏的检查。基本原则是您需要将价值与以前的价值进行比较。
因此:例如:
,重置全局级别布尔变量会有一些警告,例如,当您在电流/编辑之间切换/编辑时,更改的检查将两次开火:一次用于当前的单个单选按钮,一次进行编辑。但是您只需要解决这些边缘案例即可。
这是一个未经测试的示例,您可以摆脱:
Essentially what you are asking for is dirty form checking. The basic principle is that you need to compare the value to what it was previously.
So for example:
There are some caveats, for example, when you toggle between current/edit the check changed will fire twice: once for the current radio button and once for the edit. But you just need to work around those edge cases.
Here is a largely untested example for you to go off of: