string P_Str_cmdtxt = String.Empty;
string P_Str_selectcondition = this.toolStripComboBox1.Items[this.toolStripComboBox1.SelectedIndex].ToString();
这句出现异常InvalidArgument=“-1”的值对于“index”无效。
参数名: index请问是什么原因?

解决方案 »

  1.   

    toolStripComboBox1控件沒有項目被選擇,所以this.toolStripComboBox1.SelectedIndex是-1
    用-1做數組索引,當然出錯
      

  2.   


    if (toolStripComboBox1.SelectedIndex!-1)
      string P_Str_selectcondition = toolStripComboBox1.Items[toolStripComboBox1.SelectedIndex].ToString(); 
      

  3.   

    if (toolStripComboBox1.SelectedIndex!-1)这句运行不了腻?
      string P_Str_selectcondition = toolStripComboBox1.Items[toolStripComboBox1.SelectedIndex].ToString(); 
      

  4.   

    应该是if (toolStripComboBox1.SelectedIndex!=-1)吧
      

  5.   

    if (toolStripComboBox1.SelectedIndex!=-1)
      string P_Str_selectcondition = toolStripComboBox1.Items[toolStripComboBox1.SelectedIndex].ToString();  
    这样用就会提示说"嵌入的语句不能是声明或标记语句"
      

  6.   

    if (toolStripComboBox1.SelectedIndex!=-1) 
      string P_Str_selectcondition = toolStripComboBox1.Items[toolStripComboBox1.SelectedIndex].ToString();   
    这样用就会提示说"嵌入的语句不能是声明或标记语句"