2017-12-15 7 views
1

コンボボックスから「ジュエリー」を選択すると「txt_qty & label6」が表示されますが、「textBox5 & label18」を選択すると表示されません。助けてくださいコンボボックス選択時にC#:if文エラーが発生しました

private void combo_main_type_SelectedIndexChanged(object sender, EventArgs e) 
    { 

     if ((string)combo_main_type.SelectedItem == "Jewelry") 
     { 
      txt_qty.Visible = true; 
      label6.Visible = true; 
      txt_qty.Location = new System.Drawing.Point(213, 343); 
      label6.Location = new System.Drawing.Point(40, 348); 
     } 
     else if ((string)combo_main_type.SelectedItem == "") 
     { 
      txt_qty.Visible = false; 
      label6.Visible = false; 

     } 
     else if ((string)combo_main_type.SelectedItem == "Gem") 
     { 
      textBox5.Visible = true; 
      label18.Visible = true; 
      textBox5.Location = new System.Drawing.Point(213, 343); 
      label18.Location = new System.Drawing.Point(40, 348); 
     } 
     else 
     { 
      textBox5.Visible = false; 
      label18.Visible = false; 
     } 


    } 
+0

txt_qtyとlabel6をfalseにする必要があります。 –

+0

はい私もそれを行いました..しかし、それでもまだ動作していません –

答えて

0

あなたがする必要があるのは以下のとおりです。

private void combo_main_type_SelectedIndexChanged(object sender, EventArgs e) 
{ 

    if ((string)combo_main_type.SelectedItem == "Jewelry") 
    { 
     txt_qty.Visible = true; 
     label6.Visible = true; 
     txt_qty.Location = new System.Drawing.Point(213, 343); 
     label6.Location = new System.Drawing.Point(40, 348); 
     textBox5.Visible = false; 
     label18.Visible = false; 
    } 
    else if ((string)combo_main_type.SelectedItem == "Gem") 
    { 
     textBox5.Visible = true; 
     label18.Visible = true; 
     textBox5.Location = new System.Drawing.Point(213, 343); 
     label18.Location = new System.Drawing.Point(40, 348); 
     txt_qty.Visible = false; 
     label6.Visible = false; 
    } 
    else 
    { 
     textBox5.Visible = false; 
     label18.Visible = false; 

     txt_qty.Visible = false; 
     label6.Visible = false; 
    } 

} 
+0

まだjewelleyのためだけに表示されていますが、Gemではありません..私はGemを選択したときに空です。 –

+0

フォームのテキストボックスを作って、 False –

+0

コードをデバッグしましたか?それは宝石のブロックであればelseを実行しますか? –

関連する問題