C#组合框添加值后无响应

时间:2018-06-22 13:56:33

标签: c# winforms combobox ftp

我试图将项目从ftp服务器添加到组合框,然后根据选择的值使用该值填充其他组合框。这仅适用于我的两个价值观。这是将项目添加到组合框中的代码。

 private string FTP_SERVER()
    {
      string result = string.Empty;
      //Request location and server name---------->
       FtpWebRequest request = 
      (FtpWebRequest)WebRequest.Create("ftp://********.com" +"/" + "Products" + 
                                                                        "/");
        //Lists directory
        request.Method = WebRequestMethods.Ftp.ListDirectory;

        // set credentials
        request.Credentials = new NetworkCredential("user1","1234");//request.Credentials = new NetworkCredential(" ", " ");
        //initiaze response
        FtpWebResponse response = (FtpWebResponse)request.GetResponse();

        //reader to read response
        Stream responseStream = response.GetResponseStream();
        StreamReader reader = new StreamReader(responseStream);

        //data from file.
        result = reader.ReadToEnd();


     //Adds to drop down box for updates.
     //This is the loop that is looking through the items and adding them to the Combo box.    

     string[] y = result.Split('\n');
      foreach (string x in y)
      {
         string files = x;
         DropBox.Items.Add(files);   
      }

       response.Close();
       return result;
    }

这是我用来查看已选择的内容以了解如何填充其他组合框的代码。问题是,当我从文本框中选择一个值并点击提交时。它不能将其识别为附加值。

if (DropBox.Text == "thing1.txt") //If choose 
  Macchiato
{
  if (MessageBox.Show("Are you sure you want to check for 
                 updates for this product?", "Confirm",              
                  MessageBoxButtons.YesNo, MessageBoxIcon.Question) == 
                  DialogResult.Yes)
  {

  }
  else
  {

  }
}

谢谢您的帮助! 我只是不明白为什么它没有将其视为价值。我单击提交,组合框变为空白,什么也没有发生。它应该显示一个消息框。谢谢!

1 个答案:

答案 0 :(得分:0)

检查您的保管箱的文本不是一个好主意,为什么不使用selectedvalue?

comboBox1.SelectedItem.ToString() == "Pippo"

(甚至最好使用string.Equals)