如何在组合框项更改时用消息提示用户



我是c#的新手,我试图在combobox项更改后用消息提示用户,但是即使更改了combobox项,下面的代码也不起作用。

 namespace NormingPointTagProgrammer
{
public partial class normingPointTagProgrammer : Form
{
    public normingPointTagProgrammer()
    {
        InitializeComponent();
        // User Message to start the tag programming
        MessageBox.Show("To Read the data programmed in a Tag, Click on READ Buttonn" +
                        "To Write data into the tag, n" +
                        "Please select the Data Format, under DATA TO PROGRAMMER frame.");
    } 
    private void dataFormatComboBox_SelectedIndexChanged(object sender, EventArgs e)
    {
        // When the user has decided to program the tag. Check the Data format selected by the user, and ask the user to
        // enter required fields based on the format selected.
        if (datFormatcomboBox.Text == "RSO")
        {
            MessageBox.Show("Within DATA TO PROGRAMMER frame, under RSO DATA from DataBase Enter the following fields: n" +
                            "Region (1-254),n" +
                            "Segment (1-255),n" +
                            "Offset (0 to 6553.5) and n" +
                            "select Type dropdown Field, Under");
         }
        else if (datFormatcomboBox.Text == "INDEX")
        {
            MessageBox.Show("Within DATA TO PROGRAMMER frame, under INDEX DATA from DataBase Enter the following fields: n" +
                            "Region (255) and n" +
                            "Index  (1-65535) ");
        }
        else if (string.IsNullOrWhiteSpace(datFormatcomboBox.Text))
        {
            MessageBox.Show("Please select the Data Format, under DATA TO PROGRAMMER frame.");
        }
        else
        {
            MessageBox.Show("Required fields not entered by the user.n" +
                            "Please enter the data to be programmed based on the Data Format selected");
        }
    }
}
}

验证您的事件是否被订阅,简写如下,例如

ComboBoxChanged += dataFormatComboBox_SelectedIndexChanged();

ComboBoxChanged += new EventHandler(dataFormatComboBox_SelectedIndexChanged);

// This will be called whenever the ComboBox changes:
      private void dataFormatComboBox_SelectedIndexChanged(object sender, EventArgs e) 
      {
         //Your datFormatcomboBox.Text logic here.
      }

本质上,无论传递给ComboBoxChanged的是什么,使用e来获得ComboBox文本的输入。

更多信息在这里:https://msdn.microsoft.com/en-us/library/aa645739(v=vs.71).aspx

希望有帮助!

最新更新