如何在适当的时间显示msgbox [英] how to show msgbox at according time

查看:92
本文介绍了如何在适当的时间显示msgbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

在WPF VB表单中,我有2个组合框.这些组合框显示YearMonth值(201703).所选值combobox1不能晚于combobox2.如果用户输入错误,则会弹出错误消息.在我的代码中

In my WPF VB form I have 2 combo boxes. Those comboboxes display YearMonth value (201703). The selected value combobox1 cannot be late then combobox2. If user did a mistake error message popup. In my code

Private Sub CBx2_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles CBx2.SelectionChanged
        If (CBx2.SelectedValue = Nothing Or CBx1.SelectedValue = Nothing) Then
            ReportButton.Visibility = Visibility.Collapsed
        Else
            If (Me.CBx1.SelectedValue > Me.CBx2.SelectedValue) Then
                Report_CC_Options.RunReport_Button.Visibility = Visibility.Collapsed
                MessageBox.Show("Period From  = " & CBx1.SelectedValue & vbCr & "cannot be later then" & vbCr & "Period To = " & CBx2.SelectedValue & ".", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Else
                ReportButton.Visibility = Visibility.Visible
            End If
        End If
End Sub

组合框2中的值更改之前的消息框弹出窗口.以后如何获得错误消息,然后在combobox2中出现新的错误选定值?

the message box popup before value in combobox2 changed. How to do to get error message later then new wrong selected value appear in combobox2?

谢谢.

推荐答案


zleug,


Hi zleug,

>>消息框弹出,然后更改combobox2中的值.以后如何获得错误消息,然后在组合框2中出现新的错误选定值?

您可以使用以下代码获取最新的选择值.

You can use the following code to get the latest select value.

    Private Sub comboBox_SelectionChanged(sender As Object, e As SelectionChangedEventArgs)
	'string text = this.comboBox.Text; //this will get the old value, not new value
	'MessageBox.Show(text);
	Dim text As String = TryCast(TryCast(TryCast(sender, ComboBox).SelectedItem, ComboBoxItem).Content, String)
	Dim text2 As String = TryCast(TryCast(e.AddedItems(0), ComboBoxItem).Content, String)
	MessageBox.Show(Convert.ToString(text & Convert.ToString(" - ")) & text2)
     End Sub

SelectionChangedEventArgs.AddedItems属性:获取包含所选项目的列表.
https ://msdn.microsoft.com/zh-cn/library/system.windows.controls.selectionchangedeventargs.addeditems%28v=VS.100%29.aspx?f = 255& MSPPError = -2147217396

SelectionChangedEventArgs.AddedItems Property:Gets a list that contains the items that were selected.
https://msdn.microsoft.com/en-us/library/system.windows.controls.selectionchangedeventargs.addeditems%28v=VS.100%29.aspx?f=255&MSPPError=-2147217396


最好的问候,


Best Regards,

吕汉楠


这篇关于如何在适当的时间显示msgbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆